• Uncategorized

About linux : How-can-I-display-Unix-day-not-seconds-in-date-formatting

Question Detail

The date is approaching (in fact, 2022-01-08), when Unix time turns 19000-days old. Currently, there is a way (namely, %s) to display Unix second in dates, but there seem to be no way to display Unix day in date formatting. How does one display Unix day in dates? If not possible, then how to introduce new date formatting symbol (%?) symbol for it?


  1. Epoch date is easy to compute just dividing Unix seconds / 86400, and works well as natural decimal time, where:

    1 dYear = 1000 days, 1 dMonth = 100 days, 1 dWeek = 10 days,
    1 dHour = 0.1 days, 1 dMinute = 0.001 days, 1 dSecond = 0.00001 days.

  2. Unix day digits, unlike Unix second‘s digits, approximate lengths of ordinary concepts of time with less than 1 order of magnitude, thus work well as decimal time and date, where:

For example, now is Unix day = 18993.94830052069 means:

 \ \\\ \ \ 30.052069 th decimal second
  \ \\\ \ 48 th decimal minute
   \ \\\  9 th decimal hour
    \ \\ 3 rd day of week
     \ \ 9 th decimal week
      \  9 th decimal month
        18 th decimal year

Unix day, interpreted this way, has the benefit of convenience of use as natural support for decimal time, so some people use it and need it.

Ultimately, I’d like to know a path for incorporating this display of time as one of the supported ways of displaying date and time in *nix systems.

Question Answer

date +%s displays the Unix second, is there a way to display Unix day with it?

No, it is not possible.

how to introduce new date formatting symbol (%?) symbol for it?

Download the sources of the date utility implementation that you are using and patch it with a custom modifier. GNU date (if you are using GNU date…) is part of GNU coretuils, see https://www.gnu.org/software/coreutils/ . Date utility follows POSIX specification.

I do not have ever encountered any need for a “number of days since epoch with fractional part” format. I do not believe it has any practical usage. I do not believe such a formatting specifier should be added to date. I see no value in it over “number of seconds since epoch with fractional part” (date +%s.%N), it’s just a change of unit. I wouldn’t want those hard-working GNU developers that are giving their work to the world for free, for them to spend time on something that has no practical application. I would like them to they spent their time with their families or on other more important things. As such, I encourage you to not take developers time, unless you can strongly prove that the community requires such a formatting specifier for practical reasons.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.