Python Time Processing---------notes

Source: Internet
Author: User

Time zone processing & formatting

Import pytzfrom datetime Import datetime# set time zone timezone = Pytz.timezone (' Asia/shanghai ') # format now_time = DateTime.Now ( TimeZone). Strftime ("%y-%m-%d%h:%m:%s") print (Now_time)

Direct Output Current Timestamp

Import timenow_timestamps = Time.time () print (now_timestamps)

DateTime Time Conversion

ImportdatetimeImport TimeImportPytzstr='2016-10-26 23:12:19'Str2datetime= Datetime.datetime.strptime (str,'%y-%m-%d%h:%m:%s')#print (str2datetime)Datetime2str= Str2datetime.strftime ('%y-%d-%m%h:%m:%s')#print (DATETIME2STR)Time_tuple=str2datetime.timetuple ()#print (time_tuple)Time2str= Time.strftime ("%y-%m-%d%h:%m:%s", Time_tuple)#print (TIME2STR)Tuple2datetime= Datetime.datetime (*time_tuple[0:6])#print (tuple2datetime)Now_timestamps=time.time ()#print (now_timestamps)Time2datetime =Datetime.datetime.fromtimestamp (now_timestamps) time_tuple=time.localtime (now_timestamps)Print(time_tuple)#time in local time zoneLocal =Datetime.datetime.fromtimestamp (now_timestamps)Print(local)#time in standard Time zoneStandard =Datetime.datetime.utcfromtimestamp (now_timestamps)Print(Standard)#time in local time zoneLocal_tz =time.localtime (now_timestamps)Print(Local_tz)#time in standard Time zoneStandard_tz =time.gmtime (now_timestamps)Print(Standard_tz)

Python Time Processing---------notes

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.