Python Time processing

Source: Internet
Author: User
Tags local time



Python Time processing

# _*_ coding: utf-8 _*_import timeimport calendarimport datetime#  Three Time forms Print ("Time stamp:",  time.time ()) in the Times module                 #  timestamp print ("Local time:",  time.localtime ())            # struct_time type of local time print ("Utc time:",  Time.gmtime ())                #  struct_time type of UTC time # time module, conversion between three time forms Time_stamp = time.time ()                           #  timestamp local_time = time.localtime (time_stamp)           #  timestamp to struct_time type local time Utc_time = time.gmtime (time_stamp)                #  time stamp to Struct_time type UTC time Time_stamp_1 = time.mktime (Local_time)           # struct_time local time-to-time stamp of type time_stamp_2 =  CALENDAR.TIMEGM (utc_time)         # struct_ The time-type UTC timestamp of the print (time_stamp, time_stamp_1, time_stamp_2) # time module, the conversion between three time forms and the string print ( Time.ctime (time_stamp))            #  timestamp to String ( local time string) print (Time.asctime (local_time))          # struct_ local time-to-string print of type Time.asctime (utc_time)             # struct_time type of UTC time to string print (Time.strftime ("%y-%m-%d, %h:%m:%s, %w",  local_time))        # struct_time type local time-to-string: Custom Format print (Time.strftime ("%y-%m-%d, %h:%m:%s,  %w ",  utc_time))    &Nbsp;    # struct_time type of UTC time-to-string: custom Format Struct_time = time.strptime (" 2016-11-15, 15:32:12, 2 ", "%y-%m-%d, %h:%m:%s, %w ")         #  string to Struct_time type # datetime the usage of the DateTime class in the module a_datetime_local =  Datetime.datetime.now ()                        #  get local time for Datetime.datetime type a_datetime_utc =  Datetime.datetime.utcnow ()                       #  get the Datetime.datetime type of UTC time Print (A_datetime_local.strftime ("% Y-%m-%d, %h:%m:%s, %w "))       # datetime.datetime type to string print (A_ Datetime_utc.strftime ("%y-%m-%d, %h:%m:%s, %w"))         #  datetime.datetime type to String a_datetime = datetime.datetime.strptime ("2016-11-15, 15:32:12, 2",  "%y-%m-%d, %h:%m:%s, %w" )     #  convert string to datetime.datetime format # datetime.datetime class and timestamp, conversion between struct_time types Time_ Stamp = a_datetime_local.timestamp ()                             #  DateTime type turn timestamp print (time_stamp) A_datetime_local = datetime.datetime.fromtimestamp (Time.time ())       #  timestamp to datetime.datetime type local time a_datetime_utc =  Datetime.datetime.utcfromtimestamp (Time.time ())     #  Timestamp to Datetime.datetime type UTC time Print (A_DATETIME_LOCAL, A_DATETIME_UTC) print (A_datetime_local.timetuple ())                  #  DateTime type goto struct_time type print (A_datetime_utc.utctimetuple ())   &nbsP;             # datetime Type Turn struct_ Time Type


This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1881909

Python Time processing

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.