Lua OS Library

Source: Internet
Author: User
Tags month name

Standard OS Library

 

OS. Rename (oldname, newname)

File rename;

 

OS. Remove (filename)

Delete an object

 

OS .exe cute (CMD)

OS .exe cute can run a system command, which is similar to the C system function.

os.execute("mkdir /tmp/cq")

 

OS. Exit (CODE)

Stop the execution of the current program. The default value of the Code parameter is true.

 

 

OS. getenv (variable)

Return the value of the environment variable. If the value does not exist, return nil.

print(os.getenv(‘HOME‘)) -- /rootprint(os.getenv(‘ROOT‘)) -- nil

 

 

OS. Time (TB)

Returns the Unix timestamp of a specified time point. If a parameter is not called, the Unix timestamp of the current time point is returned.

print(os.time())print(os.time{year=2014, month=10, day=28, hour=13})

 

The fields of the table parameter include:

Year

Year

Month

01-12

Day

01-31

Hour

00-23

Min

00-59

Sec

00-59

Isdst

Boolean value. True indicates timeout.

The year, month, and day fields are required. The default values of other fields are 12:00:00.

 

 

OS. Date (format,Sec)

OS. Data is the inverse function of OS. Time. It converts a Unix timestamp into a readable string. If 2nd parameters are omitted, the date of the current time point is returned by default ..

To generate a date table, you can use the format string "* t", for example:

tb = os.date("*t")for k,v in pairs(tb) do    print(k,v)end

Output:

hour    13min     51wday    3day     28month   10year    2014sec     58yday    301isdst   false

 

For other format strings, OS. date will format the date as a string, which is a copy of the input format string, but some of the special tags are replaced with the time and date information. All tags start with "%" and are accompanied by one character, for example:

print(os.date())                            -- Tue Oct 28 13:57:39 2014print(os.date(‘today is %A, in %B‘))        -- today is Tuesday, in Octoberprint(os.date(‘%x‘,os.time()-24*3600*7 ))   -- 10/21/14

 

All tags and their meanings are listed below:

%

Abbreviated weekly name, such as wed

%

Full name of the week, such as Wednesday

% B

Abbreviated month name, such as SEP

% B

Full name of month, such as September

% C

Date and time, for example, 09/16/14 13:43:08

% D

The day of the month, 01-31

% H

Hours in the 24-hour system, 00-23

% I

Hours in the 12-hour system, 01-12

% J

The day of the year, 001-366

% M

Minutes, 00-59

% M

Number of months, 01-12

% P

AM or PM)

% S

Seconds, 00-59

% W

The day of the week, 0-6

% X

Date, for example, 09/16/14

% X

Time, such as 13:47:20

% Y

Two-digit year, for example, 14

% Y

Complete year, such as 2014

%

Character %

 

 

 

OS. difftime (t2, T1)

Returns the time span from T1 to T2.

 

OS. Clock ()

Function OS. Clock returns the number of seconds of the current CPU time, which can be used to calculate the execution time of a piece of code.

local x = os.clock()local s = 0for i=1,10^7 do s = s + i endprint(string.format("elapsed time: %.2f\n", os.clock() - x))

 

Lua OS Library

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.