Convert Python time to Timestamp

Source: Internet
Author: User

After searching for half a day, I finally found it on the English site and thanked the rock and fans in the group.

>>> S = datetime. datetime (2009,1, 1)
>>> Time. mktime (S. timetuple ())
1230739200.0

Don't pay for a python time-based function, which is very easy to use.

We pilot a required Module
>>> Import time
Set a time format, which will be used below
>>> 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.
>>> Time. Time ()
1180759620.859
The above cannot be understood. Please change the format to see it.
>>> Time. localtime ()
(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.
>>> Time. strftime (isotimeformat, time. localtime ())
'2017-06-02 12:54:29 ′
We have defined the time format and used strftime to convert the time. If the current time is used, time. localtime () does not need to be used.

time. strftime (isotimeformat, time. localtime (time. time ()
'2017-06-02 12:54:31 '
time. strftime (isotimeformat, time. gmtime (time. time ()
'2017-06-02 04:55:02 '
the difference between gmtime and localtime is shown above.
view the time zone
time. timezone
-28800
the value above is a second value, which is the description of the difference between the current time zone and the 0 time zone.-28800 =-8*3600, that is, the UTC + 8 zone.

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.