PC의 시간을 동기화 할때 사용합니다.
API 함수 원형 입니다.
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
public extern static void Win32GetSystemTime(ref SYSTEMTIME lpSystemTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SYSTEMTIME lpSystemTime);
함수 입니다.
/// <summary>
/// 한국시간을 기준으로 합니다..(UTC는 제외)
/// </summary>
/// <param name="locTime"></param>
/// <returns></returns>
public bool SetLocalTime(DateTime locTime)
{
DateTime datatime = locTime.ToUniversalTime();
SYSTEMTIME sTime = new SYSTEMTIME();
Win32GetSystemTime(ref sTime);
sTime.wYear = (ushort)datatime.Year;
sTime.wMonth = (ushort)datatime.Month;
sTime.wDayOfWeek = (ushort)datatime.DayOfWeek;
sTime.wDay = (ushort)(datatime.Day);
sTime.wHour = (ushort)(datatime.Hour);
sTime.wMinute = (ushort)datatime.Minute;
sTime.wSecond = (ushort)datatime.Second;
sTime.wMilliseconds = (ushort)datatime.Millisecond;
if (Win32SetSystemTime(ref sTime))
{
return true;
}
else
{
return false;
}
}
사용되는 구조체 원형은 다음과 같습니다.
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
- 대표 전화 : 02) 2061 - 0753 - Fax : 02) 2061 - 0759 - Skype : devzone24
- 주소 : 서울특별시 양천구 목1동 923-14. 현대드림타워 1024호
- 기술 문의: 02) 2061-1259 김민석 기술이사
댓글 없음:
댓글 쓰기