Use examples of lua common time functions

Time:2022-4-26

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

--Gets the current Greenwich mean time

print(os.time())

 

--Get the string representation of the current time, for example: 11 / 28 / 08 10:28:37

print(os.date())

 

--Gets the string representation of the current date, such as 11 / 28 / 08

print(os.date("%x", os.time()))

 

--Gets the string representation of the current time, such as 10:28:37

print(os.date("%X", os.time()))

 

--Get the string representation of the current time, for example: 10 / 10 / 13 10:28:37

print(os.date("%c", os.time()))

 

--Get the string representation of the current time, such as: 2013-10-10 10:28:37

print(os.date("%Y-%m-%d %H:%M:%S", os.time()))

 

--Function os Clock returns the number of clock seconds spent by the CPU executing the program

local x1 = os.clock()

local s = 0

for i = 1, 10000000 do

s = s + i

end

local x2 = os.clock()

print(string.format("elapsed time: %.2f\n", x2 - x1))

local T2009_StartTime = { year=2013, month=2, day=9, hour=0, min=0, sec=0 }

local T2009_EndTime = { year=2013, month=2, day=17, hour=23, min=59, sec=59 }

 

T2009_AvtivityTime = { startTime = os.time(T2009_StartTime), endTime = os.time(T2009_EndTime) }

 

Print ('successfully loaded gift package activity, activity time: '. OS. Date ('% C ', t2009_avtivitytime. Starttime)

'~' .. os.date('%c', T2009_AvtivityTime.endTime))

 

temp = os.date("*t", os.time())

print(temp)

--[[, a table will be generated

{year = 1998, month = 9, day = 16, yday = 259, wday = 4,

 hour = 23, min = 48, sec = 10, isdst = false}

--]]

 

Recommended Today

Tomcat 9 safety reinforcement

Apache Tomcat 9 (9.0.53) – Security Considerations NUM Reinforcement content explain remarks 1 Patch installation Use the latest version of Tomcat 2 directory right Modify Tomcat directory permission to run user 3 Running authority The user running Tomcat cannot be root 4 Delete files and directories unrelated to the project Delete the directory under webapps […]