Several small examples of Lua time transformation

Source: Internet
Author: User
Tags lua

This article mainly introduces the LUA time transformation Several small examples, this article directly gives 3 paragraph example code, needs the friend to be possible to refer to under

1, the time seconds, the conversion of XX days xx xx seconds of the form

The code is as follows:

--The time of the second, the conversion of XX days xx when xx minutes xx seconds of the form

function Converttimeform (second)

Local timeday = Math.floor (second/86400)

Local timehour = Math.fmod (Math.floor (second/3600), 24)

Local Timeminute = Math.fmod (Math.floor (SECOND/60), 60)

Local Timesecond = Math.fmod (second, 60)

Return Timeday, Timehour, Timeminute, Timesecond

End

2, the time seconds, the conversion of XX minutes xx seconds of the form

The code is as follows:

Local function Formattime (time)

Local hour = Math.floor (time/3600);

Local minute = Math.fmod (Math.floor (TIME/60), 60)

Local second = Math.fmod (time, 60)

Local rttime = String.Format ("%s:%s:%s", hour, minute, second)

Return Rttime

End

3,

The code is as follows:

--Convert the number of seconds from 1990.1.1 to date

--endtime Unit Millisecond

Os.date ("%y-%m-%d%h:%m", Math.floor (endtime/1000))

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.