字符串转换为日期在bash [英] Convert string to date in bash

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

问题描述

我的格式为年月日的字符串。这是在bash一个字符串,我想要得到它转换成一个日期,使所有其他日期的功能,使它能够被使用。

I have a string in the format "yyyymmdd". It is a string in bash and I want to get it converted into a date so that all other date functions can be used on it.

20121212串入20121212日期格式%Y%M%D。

"20121212" string into "20121212" date with format "%Y%m%d".

推荐答案

这为我工作:

date -d '20121212 7 days'
date -d '12-DEC-2012 7 days'
date -d '2012-12-12 7 days'
date -d '2012-12-12 4:10:10PM 7 days'
date -d '2012-12-12 16:10:55 7 days'

然后就可以输出格式化参数添加'+%Y%M%D'

then you can format output adding parameter '+%Y%m%d'

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

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