Skip to main content
added 86 characters in body
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

With zsh you could use the strftime builtin (available via zsh/datetime) with -r (reverse):

strftime -r format timestring

which uses format to parse the timestring and output the number of seconds since epoch:

zmodload zsh/datetime
strftime -r %Y-%b-%d 2015-Jul-13
1436734800

This errors out if the date is invalid:

strftime -r %Y-%b-%d 2015-Jul-33            
zsh:strftime:5: format not matched

You can thenalso convert the seconds since epoch to anotherany other standard/custom date format with date if needed etc.e.g.

strftime '%A, %B %d, %Y' 1447970400
Friday, November 20, 2015

With zsh you could use the strftime builtin (available via zsh/datetime):

strftime -r format timestring

which uses format to parse the timestring and output the number of seconds since epoch:

zmodload zsh/datetime
strftime -r %Y-%b-%d 2015-Jul-13
1436734800

This errors out if the date is invalid:

strftime -r %Y-%b-%d 2015-Jul-33            
zsh:strftime:5: format not matched

You can then convert the seconds since epoch to another format with date if needed etc...

With zsh you could use the strftime builtin (available via zsh/datetime) with -r (reverse):

strftime -r format timestring

which uses format to parse the timestring and output the number of seconds since epoch:

zmodload zsh/datetime
strftime -r %Y-%b-%d 2015-Jul-13
1436734800

This errors out if the date is invalid:

strftime -r %Y-%b-%d 2015-Jul-33
zsh:strftime:5: format not matched

You can also convert the seconds since epoch to any other standard/custom date format e.g.

strftime '%A, %B %d, %Y' 1447970400
Friday, November 20, 2015
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

With zsh you could use the strftime builtin (available via zsh/datetime):

strftime -r format timestring

which uses format to parse the timestring and output the number of seconds since epoch:

zmodload zsh/datetime
strftime -r %Y-%b-%d 2015-Jul-13
1436734800

This errors out if the date is invalid:

strftime -r %Y-%b-%d 2015-Jul-33            
zsh:strftime:5: format not matched

You can then convert the seconds since epoch to another format with date if needed etc...