While researching a different approach to convert a timestamp like
2015-09-08 11:07:35
to
1441703255
I found a lot of pretty commonly found solutions use e.g.
date +%s --date "2015-09-08 11:07:35"
awk, perl or similiar solutions.
However SE conversion answer seems to use printf
for that conversion on a "newer" bash version.
As this is to be used in a script with some limitations I rather not have to rely on date
for that, but instead try an approach which might be faster.
My relevant tries so far:
printf '%(%s)2015-09-08 11:07:35'
bash: printf: warning: `2': invalid time format specification
printf '%(%s)T' "2015-09-08 11:07:35"
bash: printf: 2015-09-08 11:07:35: invalid number
It seems I am unable to correctly use printf
as I lack the exact manual where the dateformat string is described.
The manpage and info coreutils 'printf invocation'
did not help me solve this issue.
bash version is
bash --version
GNU bash, Version 4.3.11(1)-release (x86_64-pc-linux-gnu)
printf '%(%s)T' "2015-09-08 11:07:35"
works in ksh93, not bash. If you want a shell with strptime capability, your options are ksh93 and zsh.