转换日期时间字符串在bash命令UNIX时间戳 [英] Convert date time string to UNIX timestamp in bash command

查看:264
本文介绍了转换日期时间字符串在bash命令UNIX时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日期时间字符串的格式如下:2012年6月12日7时21分22秒。我怎样才能将其转换为UNIX时间戳?

The date time string is in the following format: 06/12/2012 07:21:22. How can I convert it to UNIX timestamp?

推荐答案

什么你要找的是日期--date = '06 /二千零十二分之一十二七时21分22秒+%的。请记住,这是假定你使用GNU的coreutils,既是 - 日期%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.

日期的其他版本请参考相应的手册页。

Consult the appropriate manual page for other versions of date.

这篇关于转换日期时间字符串在bash命令UNIX时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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