How can I get the epoch if I have a string in the following format?
1/30/2017 11:14:55 AM
The following does not work:
$ date -j '1/30/2017 11:14:55 AM' +'%m/%d/%Y %H:%M:%S'
date: illegal time format
How can I get the epoch if I have a string in the following format?
1/30/2017 11:14:55 AM
The following does not work:
$ date -j '1/30/2017 11:14:55 AM' +'%m/%d/%Y %H:%M:%S'
date: illegal time format
Just specify the input format with -f:
$ date -jf '%m/%d/%Y %H:%M:%S %p' '1/30/2017 11:14:55 AM' '+%m/%d/%Y %H:%M:%S'
01/30/2017 11:14:55
What goes after + is the output format. If you want the epoch time, that would be +%s.
(note that there's nothing bash-specific in that code. That code would be parsed the same in any shell, even non-Bourne-like ones. date is not a bash builtin command, here it's the date command found on the file system, specifically one that supports those -f/-j BSD extensions. On non-BSD systems that command is likely not to work regardless of whether the shell is bash or other. Some shells like zsh or ksh93 have time-parsing capabilities built in but not bash)