在Python中解析非零填充时间戳 [英] Parsing non-zero padded timestamps in Python

查看:152
本文介绍了在Python中解析非零填充时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从以下时间戳获取datetimes: 3/1/2014 9:55 with datetime.strptime 或相当的东西。

I want to get datetimes from timestamps like the following :3/1/2014 9:55 with datetime.strptime, or something equivalent.

月份,月份和小时不是零填充,但似乎没有列出一个格式化指令这里,可以自动解析。

The month, day of month, and hour is not zero padded, but there doesn't seem to be a formatting directive listed here that is able to parse this automatically.

最好的做法是什么?谢谢!

What's the best approach to do so? Thanks!

推荐答案

strptime 能够解析非填充值。它们被注意到在格式代码表中填充的事实适用于 strftime 的输出。所以你可以使用

strptime is able to parse non-padded values. The fact that they are noted as being padded in the formatting codes table applies to strftime's output. So you can just use

datetime.strptime(datestr, "%m/%d/%Y %H:%M")

这篇关于在Python中解析非零填充时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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