本文介绍了本周星期一的打印日期(以bash为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以当年星期一的格式YYYYMMdd(例如今天将为20110627)格式获取日期。从明天到星期天,我还想打印星期一(今天)的日期。然后下周,重复这个过程

I want to get a date in the format 'YYYYMMdd' (for example, today would be 20110627) format for the monday of the current week. From tomorrow through to Sunday I'd like to still print out Mondays (today's) date. Then Next week, repeat the process

推荐答案

#monday
date -dmonday +%Y%m%d

#last monday
date -dlast-monday +%Y%m%d

#next monday
date -dnext-monday +%Y%m%d

#two mondays from now
date -d'monday+14 days' +%Y%m%d

#two mondays ago
date -d'monday-14 days' +%Y%m%d

#although, if you fancy yourself an Abraham Lincolin
date -d'monday-fortnight ago' +%Y%m%d #2 weeks ago
date -d'monday+fortnight' +%Y%m%d #2 weeks from now

#Monday Next Year
date -d'52+monday' +%Y%m%d

#However, Monday Last Year
date -d'52-monday' +%Y%m%d  #DOES NOT  WORK




#you can try a day other than monday
#and format this differently.

如果一个范围是你以后可能需要做一些事情

if a range is what your after you may need to do a few things

#Tuesday to Sunday
#since today is monday, I'll use Tuesday
echo `date -dtuesday +%Y%m%d-``date -dnext-sunday +%Y%m%d`

输出:

注意这只适用于GNU日期

note this only works on GNU date

我已经读过:

这篇关于本周星期一的打印日期(以bash为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:31