그 반대로, DateTime --> WMI 시간 형식으로 변경하는 스크립트 입니다. 본 스크립트는 Windows 내장 Microsoft.CmdLib 컴포넌트에서 제공해 주는 함수중 하나 입니다.
Function changeToWMIDateTime(ByVal strDateTime,strTimeZone)
ON ERROR RESUME NEXT
Err.Clear
Dim arrDateTimeCheck ' to store the date-time values
Dim strDate ' to store temporary date value
Dim arrDate ' array to store date values(MMDDYYYY)
Dim strMonth ' to store Month value
Dim strYear ' to store Year value
Dim strDay ' to store Day value
Dim strTime ' to store temporary date value
Dim arrTime ' array to store date values(MMDDYYYY)
Dim i ' for looping
Dim iYearPosition ' Used to hold the position of year in Date.
' input strDateTime is like "mm/dd/yy|yyyy,hh:mm:ssAM|PM"
' input Timezone is like "'+|-' UUU"
arrDateTimeCheck = split(strDateTime,",")
' Finally format the input like "YYYYMMDDHHMMSS.000000+TIMEZONE"
' first format the month and day. Append the four digit year
' Conver the 2 digit year to 4 digit year.
' If there are already 4 digits, then don't worry.
iYearPosition = InstrRev(arrDateTimeCheck(0),"/")
If Len(arrDateTimeCheck(0)) - iYearPosition = 2 Then
arrDateTimeCheck(0) = Left(arrDateTimeCheck(0),iYearPosition) & Left(Year(Date),2) &
Right(arrDateTimeCheck(0),2)
End If
'now date is mm/dd/yyyy
'Spliting the array for month,day,year
arrDate = split(arrDateTimeCheck(0) , "/" )
' The date, month must be of 2 digits
' If they are of single digit length < 2, append a "0"
For i=0 to ubound(arrDate) - 1
If Len(arrDate(i)) < 2 then
arrDate(i) = "0" & arrdate(i)
End If
Next
strMonth = arrDate(0)
strDay = arrDate(1)
strYear = arrDate(2)
'for 'YYYYMMDD' Pattern
strDate = strYear & strMonth & strDay
' Take the Time for formating
strTime = arrDateTimeCheck(1)
'NOW arrDateTimeCheck(1)="HH:MM:SSAM|PM".
'here formating Time 24Hours independent of Locale separator
'Spliting the array for HH MM SS
arrTime = split(strTime , ":" )
'Looking for [A|P]M string
If Instr(1,Lcase(arrTime(2)),Lcase("AM"),VBBinaryCompare) > 0 Then
'AM Conversion for 24H
If arrTime(0) >= 12 Then
arrTime(0) = arrTime(0) - 12
End If
Else
'PM Conversion for 24H
If arrTime(0) < 12 Then
arrTime(0) =arrTime(0) + 12
End If
End If
'Adding leading zero if third element is S[A|P]M
If Len( arrTime(2)) = 3 then arrTime(2) = "0" & arrTime(2)
'Removing AM|PM from third element in the array
arrTime(2) =Mid(arrTime(2),1,2)
' The hours, mins and secs must be of 2 digits
' If they are of single digit i.e Len < 2 , append a "0"
For i=0 to ubound(arrTime)
If Len(arrTime(i)) < 2 then
arrTime(i) = "0" & arrTime(i)
End If
Next
strTime = Join( arrTime ,"") ' formatting as HHMMSS
' Return the total format as "YYYYMMDDHHMMSS.000000+TIMEZONE"
ChangeToWMIDateTime = strDate & strTime & ".000000" & strTimeZone
End Function
ON ERROR RESUME NEXT
Err.Clear
Dim arrDateTimeCheck ' to store the date-time values
Dim strDate ' to store temporary date value
Dim arrDate ' array to store date values(MMDDYYYY)
Dim strMonth ' to store Month value
Dim strYear ' to store Year value
Dim strDay ' to store Day value
Dim strTime ' to store temporary date value
Dim arrTime ' array to store date values(MMDDYYYY)
Dim i ' for looping
Dim iYearPosition ' Used to hold the position of year in Date.
' input strDateTime is like "mm/dd/yy|yyyy,hh:mm:ssAM|PM"
' input Timezone is like "'+|-' UUU"
arrDateTimeCheck = split(strDateTime,",")
' Finally format the input like "YYYYMMDDHHMMSS.000000+TIMEZONE"
' first format the month and day. Append the four digit year
' Conver the 2 digit year to 4 digit year.
' If there are already 4 digits, then don't worry.
iYearPosition = InstrRev(arrDateTimeCheck(0),"/")
If Len(arrDateTimeCheck(0)) - iYearPosition = 2 Then
arrDateTimeCheck(0) = Left(arrDateTimeCheck(0),iYearPosition) & Left(Year(Date),2) &
Right(arrDateTimeCheck(0),2)
End If
'now date is mm/dd/yyyy
'Spliting the array for month,day,year
arrDate = split(arrDateTimeCheck(0) , "/" )
' The date, month must be of 2 digits
' If they are of single digit length < 2, append a "0"
For i=0 to ubound(arrDate) - 1
If Len(arrDate(i)) < 2 then
arrDate(i) = "0" & arrdate(i)
End If
Next
strMonth = arrDate(0)
strDay = arrDate(1)
strYear = arrDate(2)
'for 'YYYYMMDD' Pattern
strDate = strYear & strMonth & strDay
' Take the Time for formating
strTime = arrDateTimeCheck(1)
'NOW arrDateTimeCheck(1)="HH:MM:SSAM|PM".
'here formating Time 24Hours independent of Locale separator
'Spliting the array for HH MM SS
arrTime = split(strTime , ":" )
'Looking for [A|P]M string
If Instr(1,Lcase(arrTime(2)),Lcase("AM"),VBBinaryCompare) > 0 Then
'AM Conversion for 24H
If arrTime(0) >= 12 Then
arrTime(0) = arrTime(0) - 12
End If
Else
'PM Conversion for 24H
If arrTime(0) < 12 Then
arrTime(0) =arrTime(0) + 12
End If
End If
'Adding leading zero if third element is S[A|P]M
If Len( arrTime(2)) = 3 then arrTime(2) = "0" & arrTime(2)
'Removing AM|PM from third element in the array
arrTime(2) =Mid(arrTime(2),1,2)
' The hours, mins and secs must be of 2 digits
' If they are of single digit i.e Len < 2 , append a "0"
For i=0 to ubound(arrTime)
If Len(arrTime(i)) < 2 then
arrTime(i) = "0" & arrTime(i)
End If
Next
strTime = Join( arrTime ,"") ' formatting as HHMMSS
' Return the total format as "YYYYMMDDHHMMSS.000000+TIMEZONE"
ChangeToWMIDateTime = strDate & strTime & ".000000" & strTimeZone
End Function
시간 형식은,. "mm/dd/yy|yyyy,hh:mm:ssAM|PM" 입니다.
즉,. 월/일/년,시:분:초오전/오후
예제,. wscript.echo changeToWMIDateTime("05/22/2008","+540")
댓글 없음:
댓글 쓰기