Python Module--time module

Source: Internet
Author: User

1. Time stamp

1 Import  Time 2 # ------->> Timestamps 3 Print (Time.time ())
1 1525418832.2835853

2. Structured time

1 # ------->>  structured time 2print(Time.localtime ())3print (Time.gmtime ()) 4 Print (Time.localtime (). Tm_mday)
1 time.struct_time (tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=15, tm_min=28, tm_sec=32, tm_wday=4, tm_yday= 124, tm_isdst=0)2 time.struct_time (tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=7, tm_min=28, tm_ Sec=32, tm_wday=4, tm_yday=124, tm_isdst=0)3 4

3. The structured time is turned into time stamp

1 # ------->> turn a structured time into a timestamp 2 Print (Time.mktime (Time.localtime ()))
1 1525418978.0

4. Structured time turns into string time

1 # ------->> turn structured time into  string time 2print(Time.strftime ("%y-%m-%d%x ", Time.localtime ()))  #  The seconds after the second can be simplified with%x to write 3print( Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()))
1 2018-05-04 15:30:522 2018-05-04 15:30:52

5. The string time is converted into structured time

1 # ------->> Turn string time into structured time 2 Print (Time.strptime ("2018-5-4 16:10:9","%y-%m-%d%x"))
Time.struct_time (tm_year=2018, tm_mon=5, tm_mday=4, tm_hour=16, tm_min=10, tm_sec=9, tm_wday=4, tm_yday=124, tm_isdst= -1)

6. The default simplified string time (in the form of Westernization)

1 Print (Time.asctime ()) 2 Print (Time.ctime ())
1 Fri  4 15:32:39 20182 Fri May  4 15:32:39 2018

7, also similar to the time of the string

1 Import datetime 2 Print (Datetime.datetime.now ())
1 2018-05-04 15:33:57.990908

Python Module--time module

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.