String format time comparison under Python

Source: Internet
Author: User
Tags string format

Example:

1 #-*-coding=utf-8-*-2 __author__='Zhongtang'3 4 5 Import Time6strtime1='20160518010101'7Strtime2='20160518020101'8 9 #string becomes time data structureTenLocaltime1=time.strptime (Strtime1,'%y%m%d%h%m%s') OneLocaltime2=time.strptime (Strtime2,'%y%m%d%h%m%s') A  - Printtype (localtime1), localtime1 - Printtype (localtime2), localtime2 the  -  - #convert from time data structure to timestamp -time1=time.mktime (localtime1) +Time2=time.mktime (localtime2) -  + Printtype (time1), time1 A Printtype (time2), time2 at  - #Timestamps can be subtracted directly to get the difference in seconds - PrintTime2-time1

Output results

1<type'Time.struct_time'> Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=18, Tm_hour=1, Tm_min=1, Tm_sec=1, tm_wday=2, tm_yday=139, tm_ Isdst=-1)2<type'Time.struct_time'> Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=18, tm_hour=2, Tm_min=1, Tm_sec=1, tm_wday=2, tm_yday=139, tm_ Isdst=-1)3<type'float'> 1463504461.04<type'float'> 1463508061.053600.0

String format time comparison under Python

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.