The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation.
当然,用
asctime
不可能做到这一点,因为strftime
关于支持的格式字符串的行为依赖于平台。你知道吗文档中的“
strftime()
和strptime()
行为”一节中有一段关于这一点:https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
但是,不管
asctime
,您仍然可以在日志格式字符串中使用UNIX Epoch之后的秒数。还有另一个名为created
的属性:https://docs.python.org/3/library/logging.html#logrecord-attributes
因为
time.time()
在Linux和Windows上都可以工作,所以您可以在日志格式字符串中使用created
而不是asctime
。你知道吗Unix epoch格式不能使用ansic中的
strftime()
获得(毕竟,这是一种输入)。 类似地,在Python中,不能将此功能作为跨平台的功能。你知道吗但是,可以利用非特殊字符在C和Python中通过
strftime()
这一事实。 因此,您可以使用以下公认非常丑陋但有效的解决方法:或者更准确地说:
相关问题 更多 >
编程相关推荐