Sha*_*ani 4 python datetime python-2.7
我正在尝试使用strftime以下列格式打印日期:06-03-2007 05:40 PM
我写了以下代码:
import time
print time.strftime("%m-%d-%Y %T:%M%p")
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误"无效的格式字符串".这是为什么?
也许你正在寻找hour,H而不是T.检查strftime可能的选项
print time.strftime("%m-%d-%Y %H:%M%p")
Run Code Online (Sandbox Code Playgroud)
注意:Windows和Linux计算机上的行为不同.如果您看到Windows平台支持的功能,请查看此http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx
所以最好%H:%M:%S比%T在Windows 上使用.
%T 在:
print time.strftime("%m-%d-%Y %T:%M%p")
Run Code Online (Sandbox Code Playgroud)
不存在。您应该使用 %H (0-23) 或 %I (0-11)
| 归档时间: |
|
| 查看次数: |
14994 次 |
| 最近记录: |