first, you need to import Python's own module time
often used are time.time (),time.strftime (),time.strptime (),time.localtime (), Time.mktime ()
First, time.time () gets the current time stamp
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/9E/0B/wKiom1mKiWKA9wMgAAALIyJrr2s465.jpg-wh_500x0-wm_ 3-wmp_4-s_3533427305.jpg "title=" gets the current timestamp. jpg "alt=" wkiom1mkiwka9wmgaaaliyjrr2s465.jpg-wh_50 "/>
Second,time.strftime () outputs the current time string in the specified format
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/9E/0A/wKioL1mKiW2geVlRAAAUFNyKnkY567.jpg-wh_500x0-wm_ 3-wmp_4-s_591772648.jpg "title=" outputs the time string in the specified format. jpg "alt=" wkiol1mkiw2gevlraaaufnyknky567.jpg-wh_50 "/>
Third,time.strptime () Convert to time array
1. convert time to timestamp
t = "2017-08-0910:46 : "
c = time.mktime (Time.strptime (t print (c)
convert the time string into a time array, and then use the Mktime Convert to timestamp
2. Reformat time
T= "2017-08-09 10:46:30"
T1= Time.strftime ("%y%m%d---%h:%m:%s",time.strptime (t ,"%y-%m-%d%h:%m:%s"))
Print(t1)
3. time stamp converted into time
T2= 1502246790
T3= Time.strftime ("%y-%m-%d%h:%m:%s",time.localtime (T2))
Print(T3)
iv.time.localtime () time to get the tuple format
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9E/0A/wKioL1mKiXixnBQLAAAlFtt8Q5U448.jpg-wh_500x0-wm_ 3-wmp_4-s_2187299388.jpg "title=" localtime.jpg "alt=" Wkiol1mkixixnbqlaaalftt8q5u448.jpg-wh_50 "/>
The Time.localtime () method is required when the timestamp is converted to time
Wu,time.mktime () converts a time array into a timestamp (see the first example of article III)
Report:
pythonMedium Time date formatting symbols:
%y the two-digit year representation ( 00-99 )
%Y the four-digit year representation ( 000-9999 )
%m Month ( 01-12 )
%d Day of the month ( 0-31 )
%H hours of the hour ( 0-23 )
%I hours of production (01-12)
%M number of minutes ( 00=59 )
%s seconds ( 00-59 )
%a Local Simplified week name
%A Local Full week name
%b locally Simplified month name
%B Local Full month name
%c Local corresponding date representation and time representation
%j One day of the Year ( 001-366 )
%p Local a.m.. or The p.m.. the equivalent character
%u the number of weeks in a year ( 00-53 ) Sunday for the beginning of the week
%w Week ( 0-6 ), Sunday for the beginning of the week
%W the number of weeks in a year ( 00-53 ) Monday for the beginning of the week
%x Local corresponding date representation
%x local corresponding time representation
%Z the name of the current time zone
%% % number itself
If you have a problem, you can communicate. QQ Group: 610845268
This article is from the "It Bug" blog, so be sure to keep this source http://laomomo.blog.51cto.com/6595318/1954731
Python---Time and time stamp relationship transformation