Use VBS to get the function code of the UNIX timestamp _vbs

Source: Internet
Author: User
Tags time zones local time
The VBS does not have a time function similar to the C standard library, how do I get a unix timestamp? At first glance it's simple:
Copy Code code as follows:

Function Unixtime ()
Unixtime = DateDiff ("s", "01/01/1970 00:00:00", Now ())
End Function

A way to take it for granted, only to notice "January 1, 1970 0:0 0 Seconds", but ignored the "coordinated world time."

Coordinated world, also known as world standard Time or world coordination time, referred to as UTC, from the English "Coordinated Universal times". local time in mainland China is 8 hours faster than UTC, writing utc+8. If the local time is slower than the UTC time, such as Hawaii time is 10 hours slower than UTC time, will write UTC-10.

The now () function in the VBS returns a time that includes time zones, so there are some corrections to getting the Unix timestamp.
Copy Code code as follows:

Function Unixtime ()
Set objWMIService = _
GetObject ("winmgmts:\\.\root\cimv2")
Set Colitems = objWMIService.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 right way to spell.
Reference Links: Epoch & Unix Timestamp conversion Tools
Original: http://demon.tw/programming/vbs-unix-time-stamp.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.