在bash脚本中,我想花费多个日历周。
date +%G returns the year 2018
date +%V returns the current week of the current year
例如,我需要日历年
2018 = 52 calendar weeks
2017 = 52 calendar weeks
2016 = 52 calendar weeks
2015 = 53 calendar weeks
是否有一个简单的命令来计算日历周。我需要2000年,2001年,2002年,......,2018年的最后一周的数量
今天的周数是
date +%U
> 36
简单的命令就是
date -d 20151231 +'%V'
其中2015年为53.只需循环一年。
这有点hacky但是如果您提供有关年份的最后一天的日期,您可以执行以下操作:
date -j -f "%m %d %Y" "12 31 2014" +%U
>> 52
以下是解析给定“%m%d%Y” - >月/日/年的格式,在第二组引号中给出,然后您可以使用您想要的任何解析机制。因此,使用“+%U”时,应该会给出给定年份的周数。
ncal
是一个显示日历的工具。
调用ncal
(或cal
)会显示当前月份的日历。
调用ncal -w
也显示周数。
请致电ncal 2018
以显示2018年的所有月份(如果您愿意,可以显示其他月份)。
请致电qazxsw poi以显示2017年12月的日历。
很多其他选择 - 请参阅ncal 12 2017
。
例:
manual