python - python中的日期时间格式转换

标签 python date python-2.6

<分区>

我有一个包含格式时间戳的字符串

(DD/MM/YYYY HH:MM:SS AM/PM), e.g."12/20/2014 15:25:05 pm"

. 这里的时间是 24 小时格式。

我需要转换成相同的格式,但时间格式为 12 小时制。

我使用的是 python 2.6 版。

我浏览了 python 的时间库,但无法提出任何解决方案。

最佳答案

观看直播 ideOne 使用 Python datetime ,

>>> from datetime import datetime as dt
>>> date_str='12/20/2014 15:25:05 pm'

>>> date_obj = dt.strptime(date_str, '%m/%d/%Y %H:%M:%S %p')

>>> dt.strftime(date_obj, '%m/%d/%Y %I:%M:%S %p')
'12/20/2014 03:25:05 PM'

关于python - python中的日期时间格式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28828611/

相关文章:

python - 为什么 python 3 给我 "expected string or buffer"

IE8 中的 JavaScript 日期未定义/NaN

java - 在java中将时间添加到现有时间

php - Yii2 - jui datepicker 扩展 - 默认显示当前时间戳

python - 如何防止我的 Python 应用程序在到达代码末尾时自动关闭?

python - 如何让 Python 的 ElementTree 漂亮地打印到 XML 文件?

python - 错误: pip install scipy

python - A[i] 和 A[i, :] in n-dimensional(n>1) numpy array? 有什么区别

python - 在 python/django 中将变量从一种方法传递到另一种方法

Python基础数学算法函数