1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| >>> datetime.date.today() datetime.date(2016, 6, 8) >>> print(datetime.date.today()) 2016-06-08 >>> >>> datetime.date.fromtimestamp(time.time()) datetime.date(2016, 6, 8) >>> >>> datetime.datetime.now() datetime.datetime(2016, 6, 8, 2, 18, 57, 453874) >>> print(datetime.datetime.now()) 2016-06-08 02:19:08.895585 >>> datetime.datetime.now().timetuple() time.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=2, tm_min=20, tm_sec=17, tm_wday=2, tm_yday=160, tm_isdst=-1) >>> >>> datetime.datetime.now().replace(2015, 5, 9) datetime.datetime(2015, 5, 9, 2, 21, 39, 897457) >>> >>> datetime.datetime.strptime("09/05/15 7:56", "%d/%m/%y %H:%M") datetime.datetime(2015, 5, 9, 7, 56) >>> >>> datetime.datetime.now() + datetime.timedelta(days=10) datetime.datetime(2016, 6, 18, 2, 26, 46, 45019) >>> datetime.datetime.now() + datetime.timedelta(days=-10) datetime.datetime(2016, 5, 29, 2, 26, 53, 536217) >>> datetime.datetime.now() + datetime.timedelta(hours=-10) datetime.datetime(2016, 6, 7, 16, 27, 0, 717995) >>> datetime.datetime.now() + datetime.timedelta(seconds=120) datetime.datetime(2016, 6, 8, 2, 29, 7, 456727)
|