Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the inverse of time.asctime in Python

Tags:

python

time

I have a 24-character string and want to get the tuple.

E.g.:

'Fri Apr 25 12:24:47 2014'

(via time.ctime(time.time()))

like image 663
Albert Avatar asked Apr 25 '14 11:04

Albert


People also ask

What data type is returned by time Asctime ()?

Return Value The asctime() function returns a pointer to the resulting character string.

What is Asctime time?

Description. The asctime() function converts time, stored as a structure pointed to by time, to a character string. You can obtain the time value from a call to the gmtime() , gmtime64() , localtime() , or localtime64() function.


1 Answers

time.strptime() parses strings into time tuples again; the default parse format matches the output of time.ctime() and time.asctime():

>>> import time
>>> time.ctime(time.time())
'Fri Apr 25 12:12:06 2014'
>>> time.strptime(time.ctime(time.time()))
time.struct_time(tm_year=2014, tm_mon=4, tm_mday=25, tm_hour=12, tm_min=12, tm_sec=10, tm_wday=4, tm_yday=115, tm_isdst=-1)
>>> time.strptime(time.asctime())
time.struct_time(tm_year=2014, tm_mon=4, tm_mday=25, tm_hour=12, tm_min=13, tm_sec=6, tm_wday=4, tm_yday=115, tm_isdst=-1)
like image 63
Martijn Pieters Avatar answered Oct 13 '22 08:10

Martijn Pieters