SWbemDateTime 개체

SWbemDateTime 개체는 CIM(Common Information Model) datetime 값을 구문 분석하고 설정하기 위한 도우미 개체입니다. 개체 경로의 형식을 지정하고 해석하는 데 도움이 되는 SWbemObjectPath와 유사한 역할을 합니다. VBScript CreateObject 호출을 사용하여 SWbemDateTime 개체를 만들 수 있습니다.

SWbemDateTime 개체는 개체의 메서드를 사용하여 VT_DATE 또는 FILETIME 값에서 초기화하고 형식을 지정할 수 있습니다. 개체의 속성을 사용하여 값을 구성 요소 연도, 월, 일, 시간, 분, 초 또는 마이크로초로 구문 분석할 수 있습니다. SWbemDateTime 개체는 로컬 또는 UTC(협정 세계시) 값으로 형식을 지정할 수 있습니다. 자세한 내용은 날짜 및 시간 형식을 참조하세요.

SWbemDateTime은 Internet Explorer의 HTML 페이지에서 실행되는 초기화 및 스크립트에 안전한 것으로 표시된 유일한 WMI(Windows Management Instrumentation) 스크립팅 개체입니다.

멤버

SWbemDateTime 개체에는 다음과 같은 형식의 멤버가 있습니다.

메서드

SWbemDateTime 개체에는 다음과 같은 메서드가 있습니다.

메서드 설명
GetFileTime BSTR로 표현된 FILETIME 날짜 및 시간을 WMI DATETIME 형식으로 변환합니다.
GetVarDate WMI DATETIME 형식의 날짜 및 시간 값을 VT_DATE로 변환합니다.
SetFileTime WMI DATETIME 형식을 BSTR로 표현된 FILETIME 날짜 및 시간으로 변환합니다.
SetVarDate VT_DATE 형식의 날짜 및 시간을 WMI DATETIME으로 변환합니다.

속성

SWbemDateTime 개체에는 다음과 같은 속성이 있습니다.

속성 액세스 유형 설명

읽기/쓰기
CIM datetime 값의 일 구성 요소입니다.
DaySpecified
읽기/쓰기
일이 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.
Hours
읽기/쓰기
CIM datetime 값의 시간 구성 요소입니다.
HoursSpecified
읽기/쓰기
시간이 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.
IsInterval
읽기/쓰기
CIM datetime의 하나 이상의 구성 요소가 날짜가 아닌 간격을 의미함을 나타냅니다.
Microseconds
읽기/쓰기
CIM datetime 값의 마이크로초 구성 요소입니다.
MicrosecondsSpecified
읽기/쓰기
마이크로초 구성 요소가 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.

읽기/쓰기
CIM datetime 값의 분 구성 요소입니다.
MinutesSpecified
읽기/쓰기
분 구성 요소가 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.
Month
읽기/쓰기
CIM datetime 값의 월 구성 요소입니다.
MonthSpecified
읽기/쓰기
월이 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.

읽기/쓰기
CIM datetime 값의 초 구성 요소입니다.
SecondsSpecified
읽기/쓰기
초 구성 요소가 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.
UTC
읽기/쓰기
CIM datetime 값의 UTC 구성 요소입니다.
UTCSpecified
읽기/쓰기
UTC 구성 요소가 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.

읽기/쓰기
전체 CIM datetime 값입니다.
Year
읽기/쓰기
CIM datetime 값의 연도 구성 요소입니다.
YearSpecified
읽기/쓰기
연도가 지정되었거나 와일드카드로 남아 있는지 여부를 나타냅니다.

설명

WMI는 타임스탬프를 UTC(협정 세계시) 형식으로 기록합니다. UTC는 대부분의 개발자와 IT 관리자가 사용하는 형식이 아닙니다. 따라서 일반적인 문제는 UTC를 더 읽기 쉬운 것으로 변환하는 방법을 결정하는 것입니다. UTC로 작업하는 방법에 대한 자세한 내용은 WMI 작업: 날짜 및 시간WMI를 사용하여 날짜 및 시간 작업을 참조하세요. 추가 정보는 시간 및 날짜 정보 블로그 게시물을 참조할 수도 있습니다.

IsInterval 속성이 FALSE로 설정된 경우 모든 숫자 필드에 와일드카드 값이 있을 수 있습니다. 와일드카드 값이 있는 필드는 전체 필드에 별표를 포함합니다.

각 속성(예: Day)에는 DaySpecified와 같이 지정된 해당 부울 값이 있습니다. DaySpecifiedFALSE이면 값은 01과 31 사이의 숫자가 아닌 간격으로 해석됩니다. CIM datetime 값의 어디에서든 간격이 사용되는 경우 IsIntervalTRUE로 설정됩니다. 기본값은 CIM datetime 값에 하나 이상의 간격이 아닌 날짜를 포함하는 것입니다.

예를 들어 SWbemDateTime.DaySpecifiedTRUE이면 SWbemDateTime.ValueSWbemDateTime.Day의 현재 값이 포함됩니다. 그렇지 않으면 와일드카드 값입니다. 두 경우 모두 IsInterval 속성은 FALSE입니다.

예제

다음 스크립트 코드 예제에서는 SWbemDateTime 개체를 사용하여 WMI 리포지토리에서 읽은 datetime 속성 값인 Win32_OperatingSystemInstallDate 속성을 구문 분석하는 방법을 보여줍니다.

' Create a new datetime object.
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")

' Retrieve a WMI object that contains a datetime value.
for each os in GetObject( _
    "winmgmts:").InstancesOf ("Win32_OperatingSystem")

    ' The InstallDate property is a CIM_DATETIME. 
    MsgBox os.InstallDate
    dateTime.Value = os.InstallDate

    ' Display the year of installation.
    MsgBox "This OS was installed in the year " & dateTime.Year

    ' Display the installation date using the VT_DATE format.
    MsgBox "Full installation date (VT_DATE format) is " _
    & dateTime.GetVarDate

    ' Display the installation date using the FILETIME format.
    MsgBox "Full installation date (FILETIME format) is " _
    & dateTime.GetFileTime 
next
Set datetime = Nothing

다음 예제에서는 SWbemDateTime 개체를 만들고 날짜 값을 개체에 저장하고 날짜를 로컬 및 UTC(협정 세계시)로 표시하며 값을 새로 만든 클래스 및 속성에 저장하는 방법을 보여줍니다. 상수 wbemCimtypeDatetime에 대한 자세한 내용은 WbemCimtypeEnum을 참조하세요.

' Create an SWbemDateTime object.
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
' Set the value 
Const wbemCimTypeDatetime = 101

' Construct a datetime value using the intrinsic VBScript CDate
' function interpreting this as a local date/time in
' the Pacific time zone (-8 hrs GMT). Convert to CIM datetime
' using SetVarDate method. The year defaults to current year.
dateTime.SetVarDate (CDate ("January 20 11:56:32"))

' The value in dateTime displays as 
' 20000120195632.000000-480. This is the equivalent time
' in GMT with the specified offset for PST of -8 hrs.
MsgBox "CIM datetime " & dateTime

' The value now displays as B=0/2000 11:56:32 AM because the
' parameter contains the default TRUE value causing the value to be
' interpreted as a local time.
MsgBox "Local datetime " & dateTime.GetVarDate ()

' The value now displays as B=0/2000 7:56:32 PM because the
' parameter value is FALSE, which indicates a GMT time.
' non-local time.
MsgBox "Datetime in GMT " & dateTime.GetVarDate (false)

' Create a new class and add a DateTime property value.
' SWbemServices.Get returns an empty SWbemObject
' which can become a new class. SWbemObject.Path_ returns an
' SWbemObjectPath object. 
set NewObject = GetObject("winmgmts:root\default").Get
NewObject.Path_.Class = "NewClass"

' Add a new property named "InterestingDate" to the NewObject class
' and define its datatype as a CIM datetime value.
NewObject.Properties_.Add "InterestingDate", wbemCimtypeDatetime

' Set the new value of the SWbemDateTime object in the InterestingDate
' property.
NewObject.InterestingDate = dateTime.Value
MsgBox "Datetime in new object " & NewObject.InterestingDate

' Write the new class (named "NewClass") containing
' the SWbemDateTime object to the repository.
NewObject.Put_
WScript.Echo "NewClass is now in WMI repository"

' Clean up the example by deleting the new class from the repository
NewObject.Delete_

다음 스크립트 코드 예제에서는 SWbemDateTime 개체를 사용하여 WMI 리포지토리에서 읽은 속성의 간격 값을 수정하는 방법을 보여줍니다.

' Construct an interval value of 100 days, 1 hour, and 3 seconds.
dateTime.IsInterval = true 
dateTime.Day = 100
dateTime.Hours = 1
dateTime.Seconds = 3

' The datetime displays as 00000100010003.000000:000.
MsgBox "Constructed interval value " & datetime

' Retrieve an empty WMI object and add a datetime property. 
Const wbemCimTypeDatetime = 101
Set NewObject = GetObject("winmgmts:root\default").Get
NewObject.Path_.Class = "Empty"
NewObject.Properties_.Add "InterestingDate", wbemCimtypeDatetime

' Set the new value in the property and update. 
NewObject.InterestingDate = dateTime.Value
MsgBox "NewObject.InterestingDate = " & NewObject.InterestingDate

' Write the new SWbemDateTime object to the repository.
NewObject.Put_

' Delete the object.
NewObject.Delete_

다음 스크립트 코드 예제에서는 SWbemDate 개체를 사용하여 FILETIME 값을 읽는 방법을 보여줍니다.

' Create a new datetime object.
Set datetime = CreateObject("WbemScripting.SWbemDateTime")

' Set from a FILETIME value (non-local).
' Assume a timezone -7 hrs. GMT.
MsgBox "FILETIME value " & "126036951652030000"
datetime.SetFileTime "126036951652030000", false

' Displays as 5/24/2000 7:26:05 PM.
MsgBox "GMT time " & dateTime.GetVarDate   

' Set from a FILETIME value (local).
datetime.SetFileTime "126036951652030000"

' Displays as 5/25/2000 2:26:05 AM.
MsgBox "Same value in local time " & dateTime.GetVarDate
Set datetime = Nothing

다음 PowerShell 코드는 SWbemDateTime 개체의 인스턴스를 만들고 OS 설치 날짜를 검색하며 날짜를 다른 형식으로 변환합니다.

# Create swbemdatetime object
$datetime = New-Object -ComObject WbemScripting.SWbemDateTime

#  Get OS installation time and assign to datetime object
$os = Get-WmiObject -Class Win32_OperatingSystem
$dateTime.Value = $os.InstallDate

# Now display the time
"This OS was installed in the year {0}"           -f $dateTime.Year
"Full installation date (VT_DATE format) is {0}"  -f $dateTime.GetVarDate()
"Full installation date (FILETIME format) is {0}" -f $dateTime.GetFileTime() 

다음 Powershell 코드는 코드를 CIM 공급자가 사용할 준비가 된 형식으로 변환합니다.

 $time = (Get-Date)
 $objScriptTime = New-Object -ComObject WbemScripting.SWbemDateTime
 $objScriptTime.SetVarDate($time)
 $cimTime = $objScriptTime.Value

요구 사항

요구 사항
지원되는 최소 클라이언트
Windows Vista
지원되는 최소 서버
Windows Server 2008
헤더
Wbemdisp.h
유형 라이브러리
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemDateTime
IID
IID_ISWbemDateTime

추가 정보

WbemCimtypeEnum

DATETIME

스크립팅 API 개체