Linux
is just a kernel, it has no bearing on that Q&A.
With the busybox implementation of date
(GNU date
are also considering implementing a similar option; GNU and busybox date
are the two implementations commonly found on systems that use Linux as their kernel that I know that support your date -d @xxx
syntax).
$ date -D %Y%m%d%H%M%S -d 20191027163020 +%s
1572193820
With the ast-open implementation of date
(like the date
builtin of ksh93 when built as part of ast-open):
$ date -p %Y%m%d%H%M%S -d 20191027163020 +%s
1572193820
With the strftime
builtin of zsh
:
$ zmodload zsh/datetime
$ strftime -r %Y%m%d%H%M%S 20191027163020
1572193820
With current versions of GNU date
, you could transform it into a format it supports for its -d
/-f
(like 2019-10-27T16:30:20
):
t=20191027163020
printf '%s%s-%s-%sT%s:%s:%s\n' $(printf '%s\n' "$t" | fold -w2) |
date -f - +%s
Note that they all work on local time. As the timezone offset is not included in your format, it's ambiguous.
For instance, in mainland UK here, 20191027011200 could be either 1572138720 or 1572135120 as the clock showed 01:12:00 twice with one hour interval after the switch to winter time.
$ date -d @1572138720 +%Y%m%d%H%M%S
20191027011200
$ date -d @1572135120 +%Y%m%d%H%M%S
20191027011200
You may want to work with UTC times always to avoid this kind of problem (by setting the $TZ
environment variable to UTC0
for instance).