Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 日期时间strftime%s在windows上崩溃_Python 3.x_Datetime - Fatal编程技术网

Python 3.x 日期时间strftime%s在windows上崩溃

Python 3.x 日期时间strftime%s在windows上崩溃,python-3.x,datetime,Python 3.x,Datetime,我有一段代码在windows上失败,但在linux上工作: import datetime as dt ts = dt.datetime.now().__format__('%s') #ts == '1479831118' 我查看了文档(Python3.5),其中甚至没有“格式%s” 如何修复此问题并从Linux获得相同的输出 谢谢您提供的代码以秒为单位输出当前时间 我可能建议使用时间模块 这将返回相同的结果 import time ts = str(int(time.time()))

我有一段代码在windows上失败,但在linux上工作:

import datetime as dt

ts = dt.datetime.now().__format__('%s')
#ts == '1479831118'
我查看了文档(Python3.5),其中甚至没有“格式%s”

如何修复此问题并从Linux获得相同的输出


谢谢

您提供的代码以秒为单位输出当前时间

我可能建议使用
时间
模块

这将返回相同的结果

import time
ts = str(int(time.time()))