time moduleΒΆ
>>> from time import strptime >>> from time import localtime >>> import time >>> t = time.time() >>> help(strptime)Help on built-in function strptime:
- strptime(...)
strptime(string, format) -> struct_time
Parse a string to a time tuple according to a format specification. See the library reference manual for formatting codes (same as strftime()).
>>> help(time.strftime) Help on built-in function strftime:
- strftime(...)
strftime(format[, tuple]) -> string
Convert a time tuple to a string according to a format specification. See the library reference manual for formatting codes. When the time tuple is not present, current time as returned by localtime() is used.
>>> localtime() (2004, 2, 4, 13, 45, 6, 2, 35, 0) >>> t = localtime() >>> n = strptime("29/02/1968",'%d/%m/%Y') >>> n (1968, 2, 29, 0, 0, 0, 3, 60, -1) >>> time.strftime("29/02/1968") '29/02/1968'>>> t (2004, 2, 4, 13, 45, 14, 2, 35, 0) >>> time.asctime(t) 'Wed Feb 4 13:45:14 2004' >>> time.strftime(t,"%d/%m/%Y") Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: strftime() argument 1 must be string, not time.struct_time >>> time.strftime("%d/%m/%Y",t) '04/02/2004' >>>