方法五:使用pandas库
pandas库进行数据分析,获取时间戳非常简单。pandas的Timestamp对象可以很方便地获取当前时间的时间戳。示例代码
import pandas as pd
# 获取当前时间戳
timestamp = pd.Timestamp.now().timestamp()
print("当前时间戳:", timestamp)
解释
pandas的Timestamp.now()直接获取当前时间,并使用timestamp()方法输出时间戳。