Python 时间戳的 24 小时格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14700073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:12:23  来源:igfitidea点击:

24 hour format for Python timestamp

pythontimestamp

提问by LandonWO

Currently I'm creating timestamps with the Python time module. I created a string using this command

目前我正在使用 Python 时间模块创建时间戳。我使用此命令创建了一个字符串

timestamp = time.strftime('%l:%M:%S')

However, this prints the format in a 12 hours format. Is there a way I can do this in a 24 hours format so it would show up as 20:52:53 instead of 8:52:53?

但是,这会以 12 小时格式打印格式。有没有办法以 24 小时格式执行此操作,使其显示为 20:52:53 而不是 8:52:53?

Thanks!

谢谢!

采纳答案by mcd

Try

尝试

timestamp = time.strftime('%H:%M:%S')

Check out this link for info on Python time module

查看此链接以获取有关 Python 时间模块的信息

http://docs.python.org/2/library/time.html

http://docs.python.org/2/library/time.html