我想将像“26/11/05 06:00:01,057000000”这样的时代转换为使用linux的yyyy-mm-ddThh:mm:ss?
我尝试使用以下脚本没有运气:
2.
输出:
echo 26/11/05 06:00:01,057000000 | awk '{ print strftime("%Y-%m-%d %H:%M:%S",$1) }'
答案 0 :(得分:0)
#!/usr/bin/env python
import sys
from datetime import datetime
time_string = ' '.join(sys.argv[1:])
dt = datetime.strptime(time_string, '%d/%m/%y %H:%M:%S,%f000')
print(dt.isoformat())
示例(将上述代码保存到convert-time-format
并运行
chmod +x convert-time-format
):
$ ./convert-time-format 26/11/05 06:00:01,057000000
2005-11-26T06:00:01.057000