Function Code for getting Unix timestamps using VBS

Source: Internet
Author: User
Tags time zones

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

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.