Timestamp python-3.5,时间戳为YYYYmmDDHHMMSS
大家好,每个星期六的工人们! 我需要将时间戳转换为YYYYmmDDHHMMSS。以下方法效果良好Timestamp python-3.5,时间戳为YYYYmmDDHHMMSS,timestamp,python-3.5,Timestamp,Python 3.5,大家好,每个星期六的工人们! 我需要将时间戳转换为YYYYmmDDHHMMSS。以下方法效果良好 timestamp=now_var[27:38] # timestamp string dth_now=( # string date heure datetime.datetime.fromtimestamp( int(timestamp) ).str
timestamp=now_var[27:38] # timestamp string
dth_now=( # string date heure
datetime.datetime.fromtimestamp(
int(timestamp)
).strftime('%Y%m%d_%H%M%S')
) # a string
但是发出了警报
File "C:\_Python\kWh_compare.py", line 35, in <module>
).strftime('%Y%m%d_%H%M%S')
ValueError: invalid literal for int() with base 10: ''
文件“C:\\u Python\kWh\u compare.py”,第35行,在
).strftime(“%Y%m%d\u%H%m%S”)
ValueError:基数为10的int()的文本无效:“”
问题在哪里?
谢谢我不知道API,但是“fromtimestamp”是否需要字符串而不是int 否则,尝试将其拆分为多个操作
timestamp=now_var[27:38]
inttimestamp=int(timestamp)
datetimestamp=datetime.datetime.fromtimestamp(inttimestamp)
dth_now=datetimestamp.strftime('%Y%m%d_%H%M%S')
我不知道API,但可能是“fromtimestamp”需要字符串而不是int 否则,尝试将其拆分为多个操作
timestamp=now_var[27:38]
inttimestamp=int(timestamp)
datetimestamp=datetime.datetime.fromtimestamp(inttimestamp)
dth_now=datetimestamp.strftime('%Y%m%d_%H%M%S')
问题是
now\u var[27:38]=''
您可以从ValueError报告的字符串中看到这一点
像这样复制:int(“”)
如何修复取决于您试图实现的目标,一种方法可能是
timestamp='0'+now\u var[27:38]
问题是now\u var[27:38]='
您可以从ValueError报告的字符串中看到这一点
像这样复制:int(“”)
如何修复取决于您试图实现的目标,一种方法可能是timestamp='0'+now\u var[27:38]