时间和时间戳转换的处理
import datetime as dt
import time
def get_current_time_ms_to_timestamp():
return int(time.time() * 1000)
def get_current_time_day_to_timestamp():
today_0 = dt.datetime.combine(dt.date.today(), dt.time.min)
today_0_timestamp = int(time.mktime(today_0.timetuple())) * 1000
return today_0_timestamp
def get_current_time_ms():
return dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
def get_current_time_s():
return dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def timestamp_to_time(timestamp):
return dt.datetime.fromtimestamp(timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S')
def get_current_month_first_day():
return dt.datetime.strptime(dt.datetime.now().strftime('%Y-%m') + '-01', '%Y-%m-%d')
|