How does python convert the timestamp to the format of "June 12, 2017 18:24"? Thanks
import time timestamp = time.time() time.strftime('%Y年%m月%d日 %H时%M分', time.localtime(timestamp)) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence
Another complaint, when opening segmentfault in chrome will show the error of running out of memory and crashing, when will it be fixed?
I have really researched a universal method. According to my Baidu Google, it seems that this is the only one in the world?
Without further ado, here are the solution principles and solutions:
Official documentation: https://docs.python.org/3/lib...
class
time.
`struct_time`¶The type of the time value sequence returned by
gmtime()
,localtime()
, andstrptime()
. It is an object with a named tuple interface: values can be accessed by index and by attribute name. The following values are present:tm_year
tm_mon
tm_mday
tm_hour
tm_min
tm_sec
strftime()
descriptiontm_wday
tm_yday
tm_isdst
tm_zone
tm_gmtoff
Note that unlike the C structure, the month value is a range of [1, 12], not [0, 11].
In calls to
mktime()
,tm_isdst
may be set to 1 when daylight savings time is in effect, and 0 when it is not. A value of -1 indicates that this is not known, and will usually result in the correct state being filled in.When a tuple with an incorrect length is passed to a function expecting a
struct_time
, or having elements of the wrong type, aTypeError
is raised.Looking at the documentation, you can see the tuple structure returned by time.localtime(). What I want to use is the year, month, day, hour, and the first 5, so here’s the code:
Output:
Done.
Please indicate the source when reprinting, thank you.