Strftime (“%Y-% M% d-%H%M%S”) ‘2016-1024-142732’ >>> Import DateTime >>> datetime.datetime.now().strfTime (“%Y-% M% d-%H%M%S”) ‘2016-1024-142732’ >>> ‘.join(STR (datetime.date.today() -datetime.timedelta (1)).split(‘-‘)) ‘20161023’ >>> 2, string convert to time >>> dt = datetime.datetime.strptime(“2016-1024-142732″,”%Y-%m%d-%H%M%S”) >>> print dt,type(dt) 2016-10-24 14:27:32

>> DT = datetime.datetime(2016,10,11,12,13,14,15) 15) >>> dt1-dt datetime.timedelta(13, 9560, 340985) >>> print dt1-dt 13 days, Datetime.date.today () >>> dt = datetime.date.today() >>> dt datetime.date.date (2016, 10,) 24) >>> dt = dt + datetime.timedelta(2) >>> dt datetime.date(2016, 10, 26) >>> dt = datetime.datetime.now() >>> dt datetime.datetime(2016, 10, 24, 14, 48, 44, 594000) >>> dt = dt + datetime.timedelta(days = 1,microseconds = 999,milliseconds = 999,minutes = 59,hours=23,weeks=1) >>> dt datetime.datetime(2016, 11, 2, 14, 47, 45, 593999) >>> dt1 = datetime.datetime.now() >>> dt1 datetime.datetime(2016, 10, 24, 14, 52, 34, 341000) >>> (dt-dt1). Total_seconds () 777311.252999 >>> “” timedelta([days[, seconds[, microseconds[, milliseconds[, Utcnow () datetime.datetime.utcNow () datetime.datetime(2016, 10, 24, 7, 8, 4) Datetime. Datetime (2016, 10, 24, 15, 11, 58, Struct_time (tm_year=2016, tm_mon=10) >>> print dt 2016-10-24 15:11:58.836000 >>> print dt. tm_mday=24, tm_hour=15, tm_min=11, tm_sec=58, tm_wday=0, tm_yday=298, Tm_isdst =-1) >>> print dt.date() 2016-10-24 >>> print dt.time() 15:11:58.836000 >>> print dt.weekday() Print dt.isoweekday()//1 = Monday 1 >>> print dt.replace(month=1) 2016-01-24 15:11:58.836000 >>> “”” %Y the four-digit year represents (000-9999) %m month (01-12) % D day (0-31) %H 24-hour hours (0-23) %I 12-hour hours (01-12) %M minutes (00=59) %S seconds (00-59) %a Local simplified week name %A Local full week name %B Local simplified month name %B Local full month name % C Local date and time representation %j day of the year (001-366) % P 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 is the beginning of the week %W Number of weeks in a year (00-53) Monday is the beginning of the week %x Local date %x local time %Z Name of the current time zone %% % number itself from datetime import datetime,date,timedelta now = datetime.now(); nextDay = now + timedelta(days = 1); NextSecond = now + timedelta(seconds = 1); Span = now – nextDay; Print (now); print(nextDay); print(nextSecond); print(span.total_seconds()); Get the time difference in seconds

More learning materials can be obtained at Annalin1203