A little record of time stamps and readable time formats in Lua

Source: Internet
Author: User

The LUA standard library provides time-related functions os.time () and Os.date (), both of which have to be noted, and the results of both functions are added to the time zone; For example, I am now the system is gmt+8; Os.time ({year=1970, month=1, Day=1, hour=0}) calculates 28800, which is 8 60, andcalculates the number of seconds in the current table for a given time distance of 1970.1.1 08:00 time, So we get a negative number;

In the C standard library, the time () function gets the timestamp in fact is added to the time zone, that is, regardless of your system is that time zone, the function returns the distance from 1970.1.1 00:00 to the current number of seconds, for example, now is Gmt+8 00:00, then Gmt+9 is 01:00, in these two The time zone calls the time () function simultaneously, and the resulting value is the same;

The time zone only affects the readable style we convert, such as the Os.date () function, Os.date ("*t", 0) results in different time zone hour field values will not be the same, the world standard Time to gmt+0 as the reference, Beijing time to gmt+8 as the reference, the middle of 8 hours gap ;

Write this record, mainly recently wrote a game activity to open the function, the server tells the customer service end of the activity of the opening and end time (timestamp), such as 09:00-12:00, and then the client to be converted into a readable style, here is to consider the time zone, because os.date () is calculated locally, If you do not pay attention to the direct conversion of the past will be the local time to display, so if the server gives a timestamp, this is really a lot of attention. Previously written code is less involved in the local conversion of readable format, this time encountered a record, it is convenient to strengthen the next memory ...

Just say: Os.date ("*t", 0) can I get the hour field in the table as the current time zone? This means that the time zone of the current system has been obtained by this method; I'm not sure, just make a question mark.

A little record of time stamps and readable time formats in Lua

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.