"Original" uses Python to summarize the time UNIX format conversion

Source: Internet
Author: User

We can use the time module in Python Mktime method will be converted to UNIX timestamp, mktime function can only accept the corresponding time Ganso sequence. Before you do this, you need to convert the input time to a tuple sequence:

If the input time is in the specified format, you can use the Strptime () function to parse a time string into a time tuple based on the specified format.

Time.  Strptime(string[, format])      

Example: Time.strptime (' 2017-11-18 13:37:09 ', '%y-%m-%d%h:%m:%s ')

If you enter a datetime.datetime (2017, 9, 14, 15, 23, 41) format, you can convert it to a time tuple using the Timetuple () method.

Dtime = Datetime.datetime.now ()
Dtime.timetuple ()

After converting to a time-tuple sequence, you can then convert it with the Mktime function: Time.mktime (timetuple)

"Original" uses Python to summarize the time UNIX format conversion

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.