Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ISO8601 seconds format from "date" in busybox?

Without adequate examples I keep going around in circles to get the 'seconds' version of iso8601 printed out by 'date'. Please look at the help that is provided with date with busybox 1.22.1. I can't seem to understand the syntax required. Examples speaks louder than words in my experience and I haven't found anything that could be useful online.

Here is what I tried:

➤ date -I=seconds
➤ date -I SPEC='seconds'
➤ date -I seconds
➤ date -I='seconds'
➤ date -I 'seconds'
➤ date -I['seconds']
➤ date -I TIMESPEC='seconds'
➤ date -I TIMESPEC=seconds

Note I have tried to use the Ubuntu version of date and was able to figure out how to get the iso8601=seconds format of date, but not in busybox...

Here is what the help of date shows for Busybox 1.22.1:

BusyBox v1.22.1 (2014-09-26 07:33:17 CEST) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
    [-s,--set] TIME Set time to TIME
    -u,--utc        Work in UTC (don't convert to local time)
    -R,--rfc-2822   Output RFC-2822 compliant date string
    -I[SPEC]        Output ISO-8601 compliant date string
                    SPEC='date' (default) for date only,
                    'hours', 'minutes', or 'seconds' for date and
                    time to the indicated precision
    -r,--reference FILE     Display last modification time of FILE
    -d,--date TIME  Display TIME, not 'now'
    -D FMT          Use FMT for -d TIME conversion
like image 974
nndhawan Avatar asked Jul 08 '17 22:07

nndhawan


1 Answers

The documentation (i.e., the help) is confusing and doesn't lead to a pleasant experience for a simple functionality. Instead the documentation needs to be re-written such that example command line inputs are also a part of help (at least to get the syntax down). In any case, I answered my own question.

The main and very subtle difference in one of my tries that I happened to miss:

➤ date -I 'seconds'
date: invalid date 'seconds'

Was off by a hair. It needed to remove the space:

➤ date -I'seconds'
2017-07-09T17:29:54-0400

Now busybox date is happy.

like image 101
nndhawan Avatar answered Oct 24 '22 23:10

nndhawan