且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Bash 中将日期时间字符串转换为纪元

更新时间:2023-02-03 08:55:18

您正在寻找的是 date --date='06/12/2012 07:21:22' +"%s"代码>.请记住,这假设您使用的是 GNU coreutils,因为 --date%s 格式字符串都是 GNU 扩展.POSIX 未指定其中任何一个,因此即使在 POSIX 兼容系统上也没有可移植的方式进行此类转换.

What you're looking for is date --date='06/12/2012 07:21:22' +"%s". Keep in mind that this assumes you're using GNU coreutils, as both --date and the %s format string are GNU extensions. POSIX doesn't specify either of those, so there is no portable way of making such conversion even on POSIX compliant systems.

有关 date 的其他版本,请参阅相应的手册页.

Consult the appropriate manual page for other versions of date.

注意:bash --date-d 选项需要美国或 ISO8601 格式的日期,即 mm/dd/yyyyyyyy-mm-dd,不是英国、欧盟或任何其他格式.

Note: bash --date and -d option expects the date in US or ISO8601 format, i.e. mm/dd/yyyy or yyyy-mm-dd, not in UK, EU, or any other format.