For today's article, let's take a look at Python's
python time formattingPart of the content,
python formattingThis aspect of the date and time this aspect because of the use of relatively small, so may be less research on this aspect, today we come to talk about
python date formattingOne aspect of knowledge.
Formatted Date: We can use the Strftime method of the time module to format the date with the following code:
Time.strftime (format[, T])
It doesn't seem to be very difficult, so let's try this code next.
Take him into the following example to try it out:
#!/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", t Ime.localtime ()) # formatted into Sat Mar 28 22:24:24 2016 form print time.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ()) # will format string converted to timestamp a = "Sat Mar 22:24:24" Print Time.mktime (Time.strptime (A, "%a%b%d%h:%m:%s%Y"))
Take a look at the answers you get after typing:
2018-08-14 17:05:32tue 14 17:05:32 20181459175064.0
It seems to be good to finish the expected effect, interested friends can try it on their own. See if the output time is your time.
In this article, we understand how to format their current time, in fact, this operation is quite simple, do not understand the words can actually try to do, after all, hands-on practice is the best way to verify the learning. Finally, I hope that this article will give you a little help in learning about Python.
For more information, please visit the PHP Chinese Web Python tutorial section.