简体   繁体   English

如何使用Linux将dd / mm / yy hh:mm:ss转换为yyyy-mm-ddThh:mm:ss?

[英]How to convert dd/mm/yy hh:mm:ss to yyyy-mm-ddThh:mm:ss using linux?

I want to convert epoch like "26/11/05 06:00:01,057000000" to yyyy-mm-ddThh:mm:ss using linux? 我想使用Linux将“ 26/11/05 06:00:01,057000000”之类的纪元转换为yyyy-mm-ddThh:mm:ss?

I have tried using the following script with no luck: 我尝试使用以下脚本没有运气:

echo 26/11/05 06:00:01,057000000 | awk '{ print strftime("%Y-%m-%d %H:%M:%S",$1) }'

Output: 输出:

1970-01-01 01:00:26
#!/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())

Example (save the above code to convert-time-format and run 示例(保存上面的代码以convert-time-format并运行
chmod +x convert-time-format ): chmod +x convert-time-format ):

$ ./convert-time-format 26/11/05 06:00:01,057000000
2005-11-26T06:00:01.057000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM