将ISO日期转换为linux bash中的纪元以来的秒数 [英] Convert an ISO date to seconds since epoch in linux bash

查看:60
本文介绍了将ISO日期转换为linux bash中的纪元以来的秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ISO格式的日期YYYY-MM-DDTHH:SS(例如2014-02-14T12:30).我想将其转换为自epoch以来的秒数,仅使用linux bash中的date命令.

所有日期均指UTC语言环境.

我知道这个问题很容易重复...关于将日期从一种格式转换为另一种格式有数十亿个问题,但我找不到自己的特殊情况

谢谢...

解决方案

对于GNU日期,请使用-d指定要解析的日期,并使用%s

指定从纪元开始的秒数.

$ date -d"2014-02-14T12:30" +%s
1392381000

I have a date in the ISO format YYYY-MM-DDTHH:SS (e.g. 2014-02-14T12:30). I'd like to convert it in seconds since epoch using only the date command in linux bash.

All the dates refer to UTC locale.

I know that this question is easily eligible for duplicate... there are billions of questions about converting dates from one format to another but I can't find my particular scenario

thank you...

解决方案

With GNU date, specify the date to parse with -d and seconds since epoch with %s

$ date -d"2014-02-14T12:30" +%s
1392381000

这篇关于将ISO日期转换为linux bash中的纪元以来的秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆