Epoch time
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Epoch time




Pages (4): [1] 2 3 4 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Epoch time  
Gnarlodious


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-18-04 03:42 PM

Is there a shell command to return seconds since 1/1/1970?

Google shows several years worth of hemming & hawing over the issue.

Or is there some module I can download?

The reason is, Apache's dynamic logfiles.

Thanks

-- Gnarlie






[ Post a follow-up to this message ]



    Re: Epoch time  
James Willmore


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-18-04 03:42 PM

On Sat, 17 Apr 2004 03:31:39 +0000, Gnarlodious wrote:

> Is there a shell command to return seconds since 1/1/1970?
>
> Google shows several years worth of hemming & hawing over the issue.
>
> Or is there some module I can download?
>
> The reason is, Apache's dynamic logfiles.

If you have the GNU version of the `date` command:

date +%s

If you want, you could try using PERL :-)  There are *many* different ways
to use/print/etc time.  The quick and dirty one-liner is:

perl -e 'print time,"\n"'

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Let He who taketh the Plunge Remember to return it by Tuesday.







[ Post a follow-up to this message ]



    Re: Epoch time  
Peter J. Acklam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-18-04 03:42 PM

James Willmore <jwillmore@remove.adelphia.net> wrote:

> The quick and dirty one-liner is:
>
> PERL -e 'print time,"\n"'

$ PERL -le 'print time'
1082194446

I don't see anything dirty about this.

Peter

--
Peter J. Acklam - pjacklam@online.no - http://home.online.no/~pjacklam





[ Post a follow-up to this message ]



    Re: Epoch time  
James Willmore


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-18-04 03:42 PM

On Sat, 17 Apr 2004 11:35:04 +0200, Peter J. Acklam wrote:

> James Willmore <jwillmore@remove.adelphia.net> wrote:
> 
>
>     $ PERL -le 'print time'
>     1082194446
>
> I don't see anything dirty about this.

Point taken.

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
.. Logically incoherent, semantically incomprehensible, and
legally ... impeccable!






[ Post a follow-up to this message ]



    Re: Epoch time  
Randal L. Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-18-04 06:33 PM

[vbcol=seagreen] 

Peter> I don't see anything dirty about this.

OK, so it's just quick.  Not dirty.  Rather clean, in fact.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment PERL training
!





[ Post a follow-up to this message ]



    Re: Epoch time  
Stefan Monnier


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-04 07:35 PM

>     $ PERL -le 'print time'
>     1082194446

> I don't see anything dirty about this.

Well, using `perl' generally qualifies as being dirty.


Stefan





[ Post a follow-up to this message ]



    Re: Epoch time  
Heiner Steven


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-04 09:34 PM

Gnarlodious wrote:

> Is there a shell command to return seconds since 1/1/1970?

Presenting Stephane's idea:

awk 'BEGIN {srand(); print srand()}'

Heiner
--
___ _
/ __| |_ _____ _____ _ _     Heiner STEVEN <heiner.steven@nexgo.de>
\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/





[ Post a follow-up to this message ]



    Re: Epoch time  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-25-04 08:34 PM

Gnarlodious <gnarlodiousNULL@VOID.invalid.yahoo.com> writes:

> Is there a shell command to return seconds since 1/1/1970?

This has come up enough that I've added the following to the FAQ under
the date arithmetic section:

h. Getting the number of seconds since the epoch

GNU date has the %s format option which returns the epoch
time. More portably, use awk

awk 'BEGIN {srand();print srand()}'

This works because srand() sets its seed value with the current
epoch time if not given an argument. It also returns the
previous seed value, so the second call gives the epoch time.

Depending on scheduling, when the call is actually executed,
etc, this might be off by a second.

Another way is to use PERL if you have it.

perl -e 'print time,"\n"'

Comments would be welcome before committing this.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra





[ Post a follow-up to this message ]



    Re: Epoch time  
Stefan Monnier


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 12:34 AM

>       This works because srand() sets its seed value with the current
>       epoch time if not given an argument. It also returns the
>       previous seed value, so the second call gives the epoch time.

Is this guaranteed by POSIX or somesuch, or does it just happen to work
that way on 90% of the systems ?


Stefan





[ Post a follow-up to this message ]



    Re: Epoch time  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 12:34 AM

On Sun, 25 Apr 2004 at 22:56 GMT, Stefan Monnier wrote: 
>
> Is this guaranteed by POSIX or somesuch, or does it just happen to work
> that way on 90% of the systems ?

From the POSIX man page:

srand([expr])
Set  the  seed value for rand to expr or use the time of day if
expr is omitted. The previous seed value shall be returned.


<http://www.opengroup.org/onlinepubs...lities/awk.html>

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:24 AM.      Post New Thread    Post A Reply      
Pages (4): [1] 2 3 4 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register