Perl: Time Functions

Source: Internet
Author: User

There are several time processing functions in Perl:

1,Time Function: Returns the cumulative number of seconds from January 1, January 1, 1970.

Use: My $ t = time ();

2,Localtime Function: Get the local time zone

Use: My $ T = localtime (Time ());

3,Gmtime function:Obtain Greenwich Mean Time

Use: My $ T = gmtime (Time ());

Get the formatting time (taking the localtime function as an example ):

My ($ sec, $ min, $ hour, $ mday, $ Mon, $ year, $ wday, $ yday, $ isdst) = localtime (Time ());

The first three representations in the above formulaSeconds, minutes, and hours, The three in the middle areNumber of days, number of months (counted from 0), Year (relative to January 1, 1990 ),The last three areThe day of the week (the day of the week), the day of the year, and the time of renewal.

Use sprintf to format the time, for example:

My $ format_time = sprintf ("% d-% d: % d", $ year + 1990, $ mon + 1, $ mday, $ hour, $ min, $ Sec );

The preceding figure shows the time in the format of 21:00:00.

Of course, there are more than one method. You can also use the date module of Perl to get the formatting time.

Related Article

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.