The time-related modules in Python are mostly times and datetime
If you want to get the system current timestamp: Time.time (), is a float type of data
Get system Current Time information: Time.ctime () is a str type of time string, generally less used and in development
If you want to get the current normal date string, you can simply use STR (datetime.date.today ())
There is the conversion between time and time stamps (very often):
Conversion on date-to-timestamp:
Import Datetimeimport Timet = Datetime.datetime (2014,12, 6, A, ten, ten) timestamp = Time.mktime (T.timetuple ()) Print Timest Amp
Timestamp to time-date conversion:
Import Datetimeimport Timet = Time.localtime (timestamp) timestr = Time.strftime ('%y-%m-%d%h:%m:%s ', t) print Timestr
One of the more common scenarios is:
Depending on the day of the week or the next few days
For example, I need to know 10 days of data since 2014-10-25.
In this case, we need to perform time calculations, if by nature, the transition between timestamps and time.
We can get the timestamp of 2014-10-25 by time-to-timestamp, then perform the operation on the timestamp, then
Then the result of the operation is converted into a time string, the complete code is as follows:
Import Timeimport Datetimet = Datetime.datetime (all, ten, 3600) timestamp = Time.mktime (t.timetuple ()) Timestamp + = 10 * 24t = time.localtime (timestamp) timestr = Time.strftime ('%y-%m-%d%h:%m:%s ', T)
In fact, the date module has a function to encapsulate this algorithm, the trial is not so large code, but we only talk about the principle, the process of Python time above
In fact, for any language should be such a process
Water sentence: Language tools are constantly changing, you can not cling to a language, not outdated only algorithms and thinking