Python string, timestamp, datetime time-dependent conversion

Source: Internet
Author: User

Summary of Time conversion functions
#datetime time converted to stringdefchangestr (datetime1): str1= Datetime1.strftime ('%y-%m-%d%h:%m:%s')    returnstr1#string time converted to timestampdefChangetime (str1): Unixtime= Time.mktime (Time.strptime (STR1,'%y-%m-%d%h:%m:%s'))    returnUnixtime#datetime time Conversion timestampdefChangestamp (DT1): Unixtime= Time.mktime (Time.strptime (Dt1.strftime ('%y-%m-%d%h:%m:%s'),'%y-%m-%d%h:%m:%s'))    returnUnixtime#time stamp converted to datetime timedefchangedatetime (timestamp): DT=Datetime.datetime.fromtimestamp (timestamp)returnDT#Uinx timestamp converted to local timedeflocaltime (datetime1): LocalTime= Time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (datetime1))returnlocaltime#string time conversion functiondefNormaltime (datetime1): Normaltime= Datetime.datetime.strptime (datetime1,'%y-%m-%d%h:%m:%s')    returnNormaltime1

Python string, timestamp, datetime time-dependent 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.