Get the current date in an era from a Unix shell script

How to get the current date value in an era, that is, the number of days that have passed since 1970-1-1. I need a solution in a unix shell script.

+45
unix shell epoch
Jul 07 '09 at 19:25
source share
5 answers

Refresh . The answer posted earlier here is related to a custom script that is no longer available, just because the OP indicated that date +'%s' does not work for it. For the right solutions, see the UberAlex answer and the cadrian answer . In short:

  • For a few seconds, starting with the Unix era, use date(1) as follows:

     date +'%s' 
  • For several days since the Unix era divided the result by the number of seconds per day (remember the double parentheses!):

     echo $(($(date +%s) / 60 / 60 / 24)) 
+22
Jul 07 '09 at 19:35
source share

Unix Date command will be displayed in the era

team

 date +"%s" 

http://unixhelp.ed.ac.uk/CGI/man-cgi?date

Edit: Some people watched you ask for days, so the result of this command is divided by 86,400

+125
Jul 07 '09 at 19:36
source share
 echo $(($(date +%s) / 60 / 60 / 24)) 
+9
Jul 07 '09 at 19:30
source share
 echo `date +%s`/86400 | bc 
+1
Jul 07 '09 at 19:36
source share

Depending on the language you use, this will be something simple, like

 CInt(CDate("1970-1-1") - CDate(Today())) 

Oddly enough, yesterday was day 40,000 if you use 1/1/1900 as a "zero day", like many computer systems.

-four
Jul 07 '09 at 19:27
source share



All Articles