在python中将字符串日期转换为long [英] Convert String date to long in python

查看:969
本文介绍了在python中将字符串日期转换为long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其中的一栏显示的日期时间格式为 yyyy-mm-ddTHH:MM:SSS.000Z

I have data frame which has a column full of date-time of format yyyy-mm-ddTHH:MM:SSS.000Z

例如 2019-06-17T19:17:45.000Z 。我想在python中将其转换为长类型(unix epoch time)。

For example, 2019-06-17T19:17:45.000Z. I want to convert this to long type (unix epoch time) in python.

该怎么做?

谢谢!

(我如何解析ISO 8601格式的日期?这个问题是在解析字符串。我想进行转换,因此是不同的)

(How do I parse an ISO 8601-formatted date? This question is abut parsing the string. I want to do a conversion and hence it is different)

推荐答案

使用模块时间:

import calendar
import time
calendar.timegm(time.strptime('2019-06-17T19:17:45.000Z', '%Y-%m-%dT%H:%M:%S.%fZ'))

输出:1560799065

Output: 1560799065

这篇关于在python中将字符串日期转换为long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆