# Set the default spec to use uglier is better than broken.
hour_fmt = '%I'
# If we're running on a platform that has an hour spec w/o leading zero
# then use that one instead.
if sys.platform.startswith('linux'):
hour_fmt = '%l'
elif sys.platform.startswith('win'):
hour_fmt = '%#I'
# etc
mydateformatter = DateFormatter("%b %d " + hour_fmt + ":%M %p", self._tz)
注意:请参阅编辑历史,了解下面评论中的讨论。这篇文章已经被改写以反映它们。
不能使用标准的日期转换说明符来完成,这些说明符列在python文档中(与C标准化的相同)。但是,可能有一些依赖于平台的方法来实现这种格式。像这样的代码可能会派上用场:
我已经确认
%l
可以在Linux上工作,而OP已经确认“%\\I`可以在Windows上工作。在相关问题 更多 >
编程相关推荐