1. convert string time to timestamp: a = "23:40:00" to the time array importtime timeArray = time. strptime (a, "% Y-% m-% d % H: % M: % S") is converted to the timeStamp: timeStamp = int (time. mktime (timeArray) timeStamp = 13814196002. to change the string format to a = "23:40:00", convert it to a = "23:40:00". Method: convert it to a time array, and then convert it to another format: timeArray = time. strptime (a, "% Y-% m-% d % H: % M: % S") otherStyleTime = time. strftime ("% Y/% m/% d % H: % M: % S", timeArray) 3. time stamp conversion to the specified format Date: Method 1: Use localtime () to convert to the time array, and then format it into the required format, such as timeStamp = 1381419600 timeArray = time. localtime (timeStamp) otherStyleTime = time. strftime ("% Y-% m-% d % H: % M: % S", timeArray) otherStyletime = "2013-10-10 23:40:00" Method 2: importdatetime timeStamp = 1381419600 dateArray = datetime. datetime. utcfromtimestamp (timeStamp) otherStyleTime = dateArray. strftime ("% Y-% m-% d % H: % M: % S") otherStyletime = "2013-10-10 23:40:00" 4. obtain the current time and convert it to the specified date format Method 1: importtime get the current time timestamp now = int (time. time ()-> This is the time stamp converted to another date format, such as: "% Y-% m-% d % H: % M: % S" timeArray = time. localtime (timeStamp) otherStyleTime = time. strftime ("% Y-% m-% d % H: % M: % S", timeArray) Method 2: importdatetime get the current time now = datetime. datetime. now ()-> This is the time array format converted to the specified format: otherStyleTime = now. strftime ("% Y-% m-% d % H: % M: % S") 5. obtain the time method three days ago: importtime importdatetime first obtains the date threeDayAgo = (datetime. datetime. now ()-datetime. timedelta (days = 3) to timeStamp: timeStamp = int (time. mktime (threeDayAgo. timetuple () to other string formats: otherStyleTime = threeDayAgo. strftime ("% Y-% m-% d % H: % M: % S") Note: timedelta () parameters include: days, hours, seconds, microseconds 6. given a timeStamp, calculate the time a few days ago: timeStamp = 1381419600 first converted to datetime importdatetime importtime dateArray = datetime. datetime. utcfromtimestamp (timeStamp) threeDayAgo = dateArray-datetime. timedelta (days = 3) refer to 5, which can be converted to any other format