VBS does not have a time function similar to the C standard library. How can I obtain the Unix timestamp? First glance:
Copy codeThe Code is as follows: Function UnixTime ()
UnixTime = DateDiff ("s", "01/01/1970 00:00:00", Now ())
End Function
A very promising method, I only noticed "January 1, 1970 00:00:00" and ignored "coordinated world ".
Coordinated Universal Time, also known as the world standard Time or the world coordination Time (UTC), comes from the English "Coordinated Universal Time. If the local time in mainland China is 8 hours faster than UTC, it will write UTC + 8. If it is in a region where local time is slower than UTC time, for example, Hawaii time is 10 hours slower than UTC time, it will write a UTC-10.
The Now () function in VBS returns time zones. Therefore, you need to modify the Unix timestamp.Copy codeThe Code is as follows: Function UnixTime ()
Set ob1_miservice = _
GetObject ("winmgmts: \. \ root \ cimv2 ")
Set colItems = obw.miservice. ExecQuery _
("Select * from Win32_OperatingSystem", 48)
For Each objItem in colItems
TimeZone = objItem. CurrentTimeZone
Next
UnixTime = DateDiff ("s", "01/01/1970 00:00:00", Now ())
UnixTime = UnixTime-TimeZone * 60
End Function
This is the correct method.
Reference link:Epoch & Unix Timestamp Conversion Tools
Original article: http://demon.tw/programming/vbs-unix-time-stamp.html