There are many functions under the time module that can convert common date formats. such as function time.time () to get the current timestamp, example: #!/usr/bin/python#-*-coding:utf-8-*-import time; # Introducing Time Module TICKS = Time.time () print "Current timestamp is:", ticks output is current timestamp: 1459994552.51 get current time #!/usr/bin/python#-*-coding:utf-8-*-import Timelocaltime = Time.localtime () print "local time:", localtime output to local time: Time.struct_time (tm_year=2018, tm_mon=3, tm_ Mday=12, tm_hour=22, tm_min=21, tm_sec=51, tm_wday=0, tm_yday=71, tm_isdst=0) get formatted time #!/usr/bin/python#- * * Coding:utf-8-*-import timelocaltime = time.asctime () print "local time:", localtime output to local time: Mon Mar 12 22:24:06 20 18 example #!/usr/bin/python#-*-coding:utf-8-*- import time # formatted as 2016-03-20 11:45:39 form print Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()) # formatted as Sat Mar 28 22:24:24 2016 form print time.strftime ("%a%b%d% h:%m:%s%Y ", Time.localtime ()) # convert format string to timestamp a =" Sat Mar 22:24:24 "Print Time.mktime (Time.strptime (A,"%a%b %d%h:%m:%s%Y ")) output of 2018-03-22:25:29mon Mar 22:25:29 20181459175064.0 get a month calendar The calendar module has a wide range of methods for working with calendar and monthly calendars, such as printing monthly calendars for a month: #!/usr/ bin/python#-*-coding:utf-8-*-import calendarcal = calendar.month (1) print "The following output January 2016 calendar:" Print cal; & nbsp;
Python date and time