34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import pandas as pd
|
||
import time
|
||
from datetime import datetime
|
||
|
||
# 模拟你的数据(as_of_date 是未来的时间 2025-05-16 19:19:29.767913)
|
||
data = {
|
||
"as_of_date": ["2025-05-16 19:19:29.767913"]
|
||
}
|
||
df = pd.DataFrame(data)
|
||
|
||
# 获取当前时间戳(用于对比)
|
||
current_time = time.time()
|
||
print(f"当前时间戳: {current_time}")
|
||
|
||
# 模拟你的计算逻辑
|
||
last_idx = 0 # 假设 last_idx 是 0
|
||
if pd.notna(df.at[last_idx, 'as_of_date']):
|
||
# 解析时间并转成时间戳
|
||
start_time = datetime.strptime(df.at[last_idx, 'as_of_date'], "%Y-%m-%d %H:%M:%S.%f").timestamp()
|
||
start_time1 = pd.to_datetime(df.at[last_idx, 'as_of_date']).timestamp()
|
||
print(start_time - start_time1)
|
||
print(f"as_of_date 时间戳: {start_time}")
|
||
|
||
# 计算时间差(当前时间 - 未来时间,应该是负数)
|
||
time_diff = time.time() - start_time
|
||
print(f"原始时间差(秒): {time_diff}")
|
||
|
||
# 四舍五入到 2 位小数
|
||
rounded_diff = round(time_diff, 2)
|
||
print(f"四舍五入后: {rounded_diff}")
|
||
|
||
# 计算绝对值(如果你想要正数)
|
||
abs_diff = round(abs(time_diff), 2)
|
||
print(f"绝对值(正数): {abs_diff}") |