python:datetime模块
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author: Victor
@Contact: @163.com
@Date: 2020/9/29
@function: ''
'''
import time
import datetime
from datetime import date
if __name__ == '__main__':
x = datetime.datetime.today()
print(type(x), x)
# <class 'datetime.datetime'> 2020-09-29 19:27:47.948094
x1 = date.today()
print(type(x1), x1)
# <class 'datetime.date'> 2020-09-29
y = date.today().timetuple()
print(type(y), y, y.tm_year)
# <class 'time.struct_time'> time.struct_time(tm_year=2020, tm_mon=9, tm_mday=29, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=273, tm_isdst=-1) 2020
zhengdian_time_stamp = int(time.mktime(date.today().timetuple()))
print(type(zhengdian_time_stamp), zhengdian_time_stamp)
# <class 'int'> 1601308800
y1 = datetime.datetime.fromtimestamp(zhengdian_time_stamp)
print(type(y1), y1)
# <class 'datetime.datetime'> 2020-09-29 00:00:00
z = datetime.datetime.now().replace(year=y1.year, month=y1.month, day=y1.day, hour=9, minute=0, second=0, microsecond=0)
print(type(z), z, int(z.timestamp()), type(z.timestamp()))
# <class 'datetime.datetime'> 2020-09-29 09:00:00 1601341200 <class 'float'>
基本方法剖析
pass

浙公网安备 33010602011771号