Python Time Module

Source: Internet
Author: User

In Python, there are usually several ways to represent time:

Timestamp (timestamp): Typically, a timestamp represents an offset that is calculated in seconds, starting January 1, 1970 00:00:00. We run "type (Time.time ())" and return the float type.

Formatted time string (format string)

Structured time (Struct_time): Struct_time A total of 9 elements in total nine elements: (year, month, day, hour, minute, second, week of the year, Day of the year, summer Time)


The computer knows the time can only be ' timestamp ' format, and the programmer can deal with or say that humans can understand the time is: ' Formatted time string ', ' structured time ', so there is a conversion relationship:


650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/30/835206dd92ff14fb383c1598f9aaf810.png-wh_500x0-wm_3 -wmp_4-s_2690617683.png "title=" 1036857-20170215142700722-743334012.png "alt=" 835206dd92ff14fb383c1598f9aaf810.png-wh_ "/>



Time Code:

The implementation shows that the elapsed time is output in a formatted time format, such as a "hot in a few minutes" function on a forum or Weibo.

Def timeer ():

True_time=time.time () #发布的时间

Time.sleep (#模拟过去的时间)

Time_now=time.time () #现在的时间

Dif_time=time_now-true_time

Struct_time=time.gmtime (Dif_time)

Return ('%d%d '%d '%d '%d '% (struct_time.tm_year-1970,struct_time.tm_mon-1,struct_time.tm_mday-1,struct_ Time.tm_hour, Struct_time.tm_min,struct_time.tm_sec))


Python Time Module

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.