선언:

C#

[DllImport("kernel32")]
public static extern void GetLocalTime(out SYSTEMTIME localTime);


VB.NET

<DllImport("kernel32")> _
Public Shared Sub GetLocalTime(ByRef localTime As SYSTEMTIME)
End Sub




사용 예제:

C#

using System;
using System.Runtime.InteropServices;
namespace ApiReference {
    class ApiExample {
        
        [StructLayout(LayoutKind.Sequential)]
        public struct SYSTEMTIME {
            public UInt16 wYear;
            public UInt16 wMonth;
            public UInt16 wDayOfWeek;
            public UInt16 wDay;
            public UInt16 wHour;
            public UInt16 wMinute;
            public UInt16 wSecond;
            public UInt16 wMilliseconds;
        }
        
        [DllImport("kernel32")]
        public static extern void GetLocalTime(out SYSTEMTIME localTime);
        
        public static void Main(string[] args) {
            SYSTEMTIME st;
            GetLocalTime(out st);
            Char[] days = {'일', '월', '화', '수', '목', '금', '토'};
            Console.WriteLine("현재 시간은 {0}년 {1}월 {2}일 {3}요일 {4}시 {5}분 {6}초 입니다.", st.wYear, st.wMonth, st.wDay, days[st.wDayOfWeek], st.wHour, st.wMinute, st.wSecond);
            Console.ReadKey(true);
        }
    }
}


VB.NET

Imports System
Imports System.Runtime.InteropServices
Namespace ApiReference
    Class ApiExample

        <StructLayout(LayoutKind.Sequential)> _
        Public Structure SYSTEMTIME
            Public wYear As UInt16
            Public wMonth As UInt16
            Public wDayOfWeek As UInt16
            Public wDay As UInt16
            Public wHour As UInt16
            Public wMinute As UInt16
            Public wSecond As UInt16
            Public wMilliseconds As UInt16
        End Structure

        <DllImport("kernel32")> _
        Public Shared Sub GetLocalTime(ByRef localTime As SYSTEMTIME)
        End Sub

        Public Shared Sub Main(args As String())
            Dim st As SYSTEMTIME
            GetLocalTime(st)
            Dim days As [Char]() = {"일"C, "월"C, "화"C, "수"C, "목"C, "금"C, "토"C}
            Console.WriteLine("현재 시간은 {0}년 {1}월 {2}일 {3}요일 {4}시 {5}분 {6}초 입니다.", st.wYear, st.wMonth, st.wDay, days(st.wDayOfWeek), st.wHour, _
                st.wMinute, st.wSecond)
            Console.ReadKey(True)
        End Sub
    End Class
End Namespace




예제 실행 결과:




매개 변수 설명:

localTime - 로컬 컴퓨터의 시간이 저장될 변수를 입력합니다.




API 설명:

로컬 컴퓨터의 시간을 가져옵니다.




참고:

GetLocalTime (MSDN)




비고:

SYSTEMTIME 구조체

로컬 컴퓨터의 시간이기 때문에 운영 체제의 시간과 다를 수 있습니다.


'API Reference' 카테고리의 다른 글

41. GetTempPath  (0) 2014.10.31
40. PROCESS_BASIC_INFORMATION  (0) 2014.10.31
38. GetSystemTime  (0) 2014.10.30
37. SYSTEMTIME  (0) 2014.10.30
36. SHGetFolderPath  (0) 2014.10.29

+ Recent posts