Python time module has a lot of very useful features in Python when it gets information about the timing.
time.time()
time stamp in Python to get the current time:
>>> import time>>> print time.time()1438608599.0
The time for printing here is from 1970 to the present time interval. Such a series of numbers is not the result we want, we can use the time module to format the timing of the method to deal with. By using the time.localtime()
method, the function is to format the timestamp as local time.
time.localtime(time.time())time.struct_time(tm_year=2015, tm_mon=8, tm_mday=3, tm_hour=21, tm_min=30, tm_sec=59, tm_wday=0, tm_yday=215, tm_isdst=0)
Now it looks more hopeful that the format will be the time we want. Using the time.strftime()
method to format a large string of information as we want, now the result is:
time.strftime(‘%Y-%m-%d‘,time.localtime(time.time()))‘2015-08-03 ‘time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time.time()))‘2015-08-03 21:32:12‘
time.strftime()
There are a lot of parameters that will allow you to output what you want more freely:
Here are time.strftime()
the parameters:
strftime(format[, tuple]) -> string
Outputs the specified struct_time (the default is the current time), based on the specified formatted string.
python format symbols in time Date:
%y Two-digit year representation (00-99)
%Y Four-digit year representation (000-9999)
%m Month (01-12)
One day in%d months (0-31)
%H 24-hour hours (0-23)
%I 12-hour hours (01-12)
%M minutes (00=59)
%s seconds (00-59)
%a Local Simplified Week name
%A Local Full week name
%b a locally simplified month name
%B Local Full month name
%c Local corresponding date representation and time representation
%j Day of the Year (001-366)
%p the equivalent of a local a.m. or p.m.
%u weeks of the year (00-53) Sunday is the beginning of the week
%w Week (0-6), Sunday for the beginning of the week
%W Week of the Year (00-53) Monday is the beginning of the week
%x Local corresponding date representation
%x Local corresponding time representation
%Z the name of the current time zone
Percent% of the number itself
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python time gets the formatting times