gpt4 book ai didi

linux - 如何转换dd/mm/yy hh :mm:ss to yyyy-mm-ddThh:mm:ss using linux?

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:43 30 4
gpt4 key购买 nike

我想使用 linux 将像“26/11/05 06:00:01,057000000”这样的纪元转换为 yyyy-mm-ddThh:mm:ss?

我曾尝试使用以下脚本但没有成功:

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

输出:

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())

示例(将以上代码保存到convert-time-format并运行
chmod +x 转换时间格式):

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

关于linux - 如何转换dd/mm/yy hh :mm:ss to yyyy-mm-ddThh:mm:ss using linux?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33011767/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com