【问题标题】:How to convert time string to epoch time timestamp如何将时间字符串转换为纪元时间时间戳
【发布时间】:2020-11-19 18:38:01
【问题描述】:

我正在转换 OHLC 数据帧以进行数据操作,并且我需要 datetime 列采用纪元时间格式。目前如下:

2020-11-18 14:30:00-05:00

该列返回的数据类型是“对象”,我理解的最后 6 位数字代表“美国/东部”时区。

如何正确地将整列转换为纪元时间时间戳?天呐

【问题讨论】:

  • 请添加数据示例,这样更容易帮助。您可能需要将日期列转换为适当的格式,然后在日期时间对象上使用纪元时间函数strftime.org

标签: python


【解决方案1】:

您可以使用 dateparser 获取 epoch 形式的数据:

import dateparser
dateparser.parse("2020-11-18 14:30:00-05:00").timestamp()

【讨论】:

    猜你喜欢
    • 2018-01-27
    • 2011-06-21
    • 2016-07-23
    • 2013-01-25
    • 2015-08-08
    • 2015-12-19
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多