Python3 May 26 Time module Common times conversion

Source: Internet
Author: User
Tags local time string format

Import time

Get current time:

Specify string format: Time.strftime ("%y-%m-%d%h:%m:%s")

current timestamp:time.t IME ()

Current time tuple format: Time.localtime ()

String to TIME format

Converts a time string to a tuple in the specified format <class ' time.struct_time ' >
Time.strptime ("string", Format ("%y-%m-%dt%h:%m:%sz"))

Convert the time format to a timestamp:
Time.mktime (tuple in ' class ' Time.struct_time ' format) #将时间格式元组转换为时间戳 <class ' float ' >

Time.gmtime (timestamp) converts a timestamp to a UTC time tuple
Time.localtime (timestamp) converts a timestamp to a time-tuple in the local time zone

Time.ctime (' timestamp ') converts a timestamp to a string (local time) such as Sat May 26 21:11:24 2018

Time.asctime (time tuple) converts a time format tuple to a specific fixed format string such as Sat May 26 21:11:24 2018

Python3 May 26 Time module Common times conversion

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.