迄今为止的 bash 字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1253828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:07:30 来源:igfitidea点击:
bash string to date
提问by Markus
Is there an opportunity to convert a string into a date in bash? For example: I have a time format: "%Y-%m-%dS%H:%M:%S". An example of such string is "2009-06-24S12:34:56". I need to convert this string into a date (unix timestamp) in bash. How can I do this?
是否有机会在 bash 中将字符串转换为日期?例如:我有一个时间格式:"%Y-%m-%dS%H:%M:%S". 这种字符串的一个例子是"2009-06-24S12:34:56"。我需要将此字符串转换为 bash 中的日期(unix 时间戳)。我怎样才能做到这一点?
回答by Matthew Iselin
Use
用
date --utc --date "<input string>" +%s

