Introduction to the practical application of Python time

Source: Internet
Author: User

Python time is a commonly used language for computer applications. If you have any questions about Python time, you can read the following articles to better understand it, the following is a detailed description of the article. I hope you will gain some benefits.

. We pilot a required module

 
 
  1. >>>ISOTIMEFORMAT=’%Y-%m-%d %X’ 

Let's take a look at the current time. Similar to many other languages, this is from epoch January 1, 1970 00:00:00) to the current number of seconds.

 
 
  1. >>> time.time()  
  2. 1180759620.859  

The above cannot be understood. Please change the format to see it.

 
 
  1. >>> time.localtime()  
  2. (2007, 6, 2, 12, 47, 7, 5, 153, 0)  

Localtime returns the time in tuple format. There is a function similar to it called gmtime (). The difference between the two functions is the time zone, and gmtime () returns the value of the 0 time zone, localtime returns the value of the current time zone.

 
 
  1. >>> time.strftime( ISOTIMEFORMAT, time.localtime() )  
  2. ‘2007-06-02 12:54:29′  

We have defined the time format and used strftime to convert the time. If the current Python time is used, time. localtime () does not need to be used.

 
 
  1. >>> time.strftime( ISOTIMEFORMAT, time.localtime( time.time() ) )  
  2. ‘2007-06-02 12:54:31′  
  3. >>> time.strftime( ISOTIMEFORMAT, time.gmtime( time.time() ) )  
  4. ‘2007-06-02 04:55:02′  

The difference between gmtime and localtime is shown above. View the time zone

 
 
  1. >>> time.timezone  
  2. -28800

    

The above article introduces the actual operation steps of Python time.

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.