日期转换调整

dev
Yang 4 months ago
parent 3e379403df
commit 4f7d2f018b
  1. 20
      utils/base_dataclean_pg.py

@ -240,10 +240,10 @@ def group_and_write_to_file(data_ip, data_account, data_interface, data_menu, st
# 获取当前工作目录 # 获取当前工作目录
current_dir = os.getcwd() current_dir = os.getcwd()
time_struct = time.gmtime(long(start) / 1000.0) # UTC时间 date_time = convert_utc_to_local_time(start)
date_time = time.strftime('%Y-%m-%d', time_struct) date_str = time.strftime('%Y-%m-%d', date_time)
file_path = os.path.join(current_dir, 'files/' + date_time + '.json') file_path = os.path.join(current_dir, 'files/' + date_str + '.json')
all_data = [data] all_data = [data]
@ -345,6 +345,20 @@ def merge_data(datasets):
return aggregated_data return aggregated_data
def convert_utc_to_local_time(timestamp):
# 将毫秒时间戳转换为秒
seconds_since_epoch = long(timestamp) / 1000.0
# 使用 gmtime() 得到 UTC 时间结构体
time_struct_utc = time.gmtime(seconds_since_epoch)
# 将 UTC 时间转换为北京时间(东八区),即加 8 小时
time_struct_beijing = time.mktime(time_struct_utc) + (8 * 60 * 60)
# 将时间戳转换回 struct_time
time_struct_beijing = time.localtime(time_struct_beijing)
return time_struct_beijing
#入口 #入口
def entry(start,end): def entry(start,end):

Loading…
Cancel
Save