3

On OpenBSD 6.3 I can see:

foo# date
Sun Apr  1 17:00:45 CEST 2018
foo#
foo# date -d "Sun Apr  1 17:00:45 CEST 2018" +%s
1522594858
foo# date
Sun Apr  1 17:00:59 CEST 2018
foo#

that "date" doesn't supports the usual conversion.

The https://www.epochconverter.com/ says that the 1522594858 is:

Your time zone: Sunday, April 1, 2018 5:00:58 PM GMT+02:00 DST

So the date command I issued only returned the unix timestamp of the CURRENT time, not the time that I have given to convert: "Sun Apr 1 17:00:45 CEST 2018".

The Question: how to convert a given date to unix timestamp on OpenBSD? If not with the "date" command, what other shell tools could do it?

First I started to read: https://man.openbsd.org/date - but didn't find anything about converting to unix timestamp. Then I tried to google for many examples, but didn't helped.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Hessnov
  • 581
  • 10
  • 27
  • 1
    The man page also mentions a `-j` flag. That seems like it could be useful. But it seems like the input format must be `YYmmddHHMMSS` (unlike FreeBSD, there is no `-f` flag) – Mikel Apr 01 '18 at 15:36

1 Answers1

3

The OpenBSD date utility is used to

  1. set the date and/or time on the system, or
  2. display the current date and/or time, or
  3. parse the time and date on the format [[[[[[cc]yy]mm]dd]HH]MM[.SS]] without setting the system's time, using the -j option.

It is not date conversion tool that is as flexible as GNU date in its parsing capabilities. If you want GNU date time/date parsing capabilities, install the coreutils port/package and use gdate instead.

Also note that the -d option for OpenBSD's date is used to set the system's value for daylight saving.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • Although that tool comes with its own problems. https://unix.stackexchange.com/a/422978/5132 – JdeBP Apr 01 '18 at 15:51