开发者

"This Friday" in bash script

开发者 https://www.devze.com 2022-12-31 07:38 出处:网络
Is there a way to calculate a time stamp for the next coming up of a week day? So for instance, with friday, i\'d like to be able to run some code that calculates that from today Wednesday 19/05/10,

Is there a way to calculate a time stamp for the next coming up of a week day?

So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it.

I know the date command can parse a given string date acc开发者_JAVA技巧ording to a format, but I can't figure out how to calculate "next friday from today"

Any idea?

EDIT: I'm on a mac


With GNU date:

date -d 'this Friday' '+%d/%m/%y'

See Relative items in date strings, part of the GNU date documentatoin. There are also examples.


Since no format was specified, it's much simpler:

date -d Fri 

'this' is assumed par default, Friday can be abbreviated. Since it is just one word - or the significant rest of it, (ask Th) it doesnt need Quotes like

 date -d "last Fri"

would.

0

精彩评论

暂无评论...
验证码 换一张
取 消