Current timestamp: Time.time ()
Current date: Time.ctime ()
Get current time:
Ymdhms = Time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
Timearray = Time.strptime (ymdhms, "%y-%m-%d%h:%m:%s")
Current Time Date stamp
currenttimestamp = Int (time.mktime (Timearray))
Print (Currenttimestamp)
Convert time stamp to date
Timearray = Time.localtime (Currenttimestamp)
ATime = Time.strftime ("%y-%m-%d%h:%m:%s", Timearray)
Print (ATime)
To convert a time string such as ' (2012-05-16 00:00:00) ' to a Unix timestamp in Python,
#!/usr/bin/env python
Import time
Import datetime
s = ' (2012-05-16-00:00:00) '
s = S.lstrip (' ('). Rstrip (') ')
D = datetime.datetime.strptime (S, "%y-%m-%d%h:%m:%s")
Print Time.mktime (D.timetuple ())
s = ' (2012-05-16-23:59:00) '
s = S.lstrip (' ('). Rstrip (') ')
D = datetime.datetime.strptime (S, "%y-%m-%d%h:%m:%s")
Print Time.mktime (D.timetuple ())
Add
Time date format symbol in Python:
%y Two-digit year representation (00-99)
%Y Four-digit year representation (000-9999)
%m Month (01-12)
Day of%d months (0-31)
%H 24-hour hours (0-23)
%I 12 Hours of 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 number of weeks in a year (00-53) Sunday is the beginning of the week
%w Week (0-6), Sunday for the beginning of the week
%w number of weeks in a 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
%%% per se