Date and Time stamp to hundredths of seconds?

Date and Time stamp to hundredths of seconds?

Post by Paul Rub » Tue, 23 Apr 2002 02:40:49



Hello all. I'd like to be able to simply retrieve
the current date and time in a format like this:

2002042111382839

which is the year, month, day, hour, min, and seconds to the hundredth place.

Is there a simple linux command that will give this information?
Thanks so much,
Sincerely,
Paul Rubin

 
 
 

Date and Time stamp to hundredths of seconds?

Post by davide_sp.. » Tue, 23 Apr 2002 03:19:16



> Hello all. I'd like to be able to simply retrieve
> the current date and time in a format like this:
> 2002042111382839

date +%Y%m%d%H%M%S

man date for more info.

Davide

 
 
 

Date and Time stamp to hundredths of seconds?

Post by bowma » Tue, 23 Apr 2002 04:34:39



Quote:> date +%Y%m%d%H%M%S

> man date for more info.

Not quite. The OP wanted hundredths of seconds. time_t, time(), struct tm,
strftime, and so forth all are based on the time_t integral number of
seconds. gettimeofday() accesses the hardware for a much finer resolution
but needs some formatting work on the seconds value.
 
 
 

Date and Time stamp to hundredths of seconds?

Post by John Hasle » Tue, 23 Apr 2002 03:56:50


Quote:Davide writes:
> date +%Y%m%d%H%M%S man date for more info.

He wants hundredths of a second.
--
John Hasler

Dancing Horse Hill
Elmwood, Wisconsin
 
 
 

Date and Time stamp to hundredths of seconds?

Post by John Hasle » Tue, 23 Apr 2002 03:52:06


Quote:Paul Rubin writes:
> I'd like to be able to simply retrieve the current date and time in a
> format like this:
> 2002042111382839
> Is there a simple linux command that will give this information?

No, but it should be doable with a simple Perl script. man Time::HiRes
--
John Hasler

Dancing Horse Hill
Elmwood, WI
 
 
 

Date and Time stamp to hundredths of seconds?

Post by Paul Rub » Wed, 24 Apr 2002 20:43:09


Hello all and thanks for your replies.
I am still unclear as to how to retrieve the hundredths of seconds.
Does anyone have more detail?

Your help is greatly appreciated.
Sincerely,
Paul Rubin


> Paul Rubin writes:
> > I'd like to be able to simply retrieve the current date and time in a
> > format like this:

> > 2002042111382839

> > Is there a simple linux command that will give this information?

> No, but it should be doable with a simple Perl script. man Time::HiRes

 
 
 

Date and Time stamp to hundredths of seconds?

Post by Paul Rub » Sun, 28 Apr 2002 07:23:29


Hello again,

What I really need is a command to enter at the prompt
to retrieve hundredths of seconds. It's OK if I retrieve
more information than this in the call; I simply need
a unix command can be entered at the prompt that will
include hundredths of seconds.

Any ideas?
Sincerely,
Paul Rubin


> Hello all and thanks for your replies.
> I am still unclear as to how to retrieve the hundredths of seconds.
> Does anyone have more detail?

> Your help is greatly appreciated.
> Sincerely,
> Paul Rubin


> > Paul Rubin writes:
> > > I'd like to be able to simply retrieve the current date and time in a
> > > format like this:

> > > 2002042111382839

> > > Is there a simple linux command that will give this information?

> > No, but it should be doable with a simple Perl script. man Time::HiRes

 
 
 

Date and Time stamp to hundredths of seconds?

Post by Grant Edwar » Sun, 28 Apr 2002 07:59:07



> What I really need is a command to enter at the prompt
> to retrieve hundredths of seconds. It's OK if I retrieve
> more information than this in the call; I simply need
> a unix command can be entered at the prompt that will
> include hundredths of seconds.

Option 1:

 python -c 'import time; print time.time()'

Option 2:

 Compile the following C program and run it:

#include <sys/time.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
  struct timeval tv;
  gettimeofday(&tv,NULL);
  printf("%ld.%06ld\n",tv.tv_sec,tv.tv_usec);
  return 0;

Quote:}

Option 3:

 There's got to be some Perl one-liner that does the same
 thing...

Quote:>> > No, but it should be doable with a simple Perl script. man Time::HiRes

Yup!

--
Grant Edwards                   grante             Yow!  I'LL get it!! It's
                                  at               probably a FEW of my
                               visi.com            ITALIAN GIRL-FRIENDS!!

 
 
 

Date and Time stamp to hundredths of seconds?

Post by Christopher Brown » Sun, 28 Apr 2002 08:51:20




>> What I really need is a command to enter at the prompt
>> to retrieve hundredths of seconds. It's OK if I retrieve
>> more information than this in the call; I simply need
>> a unix command can be entered at the prompt that will
>> include hundredths of seconds.

> Option 1:

>  python -c 'import time; print time.time()'

> Option 2:

>  Compile the following C program and run it:

> #include <sys/time.h>
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
>   struct timeval tv;
>   gettimeofday(&tv,NULL);
>   printf("%ld.%06ld\n",tv.tv_sec,tv.tv_usec);
>   return 0;
> }

> Option 3:

>  There's got to be some Perl one-liner that does the same
>  thing...

>>> > No, but it should be doable with a simple Perl script. man Time::HiRes

> Yup!

Of course, all of these options have the problem that if it takes more
than 0.01 seconds to invoke them, the result will be wrong by the time
you press the [Return] key.

The C program is likely to have the least "baggage" that gets dragged
into things.

Consider, when I run the Python version 100 times, I get a string of
measurements looking like:

1019864828.35
1019864828.39
1019864828.44
1019864828.48
1019864828.52
1019864828.56
1019864828.61
1019864828.65
1019864828.69
1019864828.73
1019864828.77
1019864828.83
1019864828.9
1019864828.95
1019864828.99
1019864829.04
1019864829.1
1019864829.16
1019864829.21
1019864829.27

It appears that it takes somewhere around .04 seconds to invoke the
script each time.

In contrast, here's what the C version generates:

1019864979.683894
1019864979.692972
1019864979.703599
1019864979.712581
1019864979.723182
1019864979.732235
1019864979.742858
1019864979.751933
1019864979.761010
1019864979.771483
1019864979.780567
1019864979.790914
1019864979.800079

It appears that it takes right around 1/100th of a second to run the C
program each time, which hopefully means that the measurement won't be
off by much more than 1/100th of a second.  (On my computer.  Yours
may behave differently...)
--

http://www.cbbrowne.com/info/spreadsheets.html
All ITS machines now have hardware for a new machine instruction --
XOI     Execute Operator Immediate.
Please update your programs.

 
 
 

Date and Time stamp to hundredths of seconds?

Post by John Hasle » Sun, 28 Apr 2002 08:47:47


Quote:Paul Rubin writes:
> I simply need a unix command can be entered at the prompt that will
> include hundredths of seconds.

Ok, here's a command:

perl -e'use Time::HiRes qw(time);printf"%.2f\n",Time::HiRes::time'
--
John Hasler

Dancing Horse Hill
Elmwood, Wisconsin

 
 
 

Date and Time stamp to hundredths of seconds?

Post by Paul Rub » Sun, 28 Apr 2002 18:42:15


Thanks again John,
When I try to run this command, I get the following error:


/usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

Any clues here?
Thanks again,
Sincerely,
Paul Rubin


> Paul Rubin writes:
> > I simply need a unix command can be entered at the prompt that will
> > include hundredths of seconds.

> Ok, here's a command:

> perl -e'use Time::HiRes qw(time);printf"%.2f\n",Time::HiRes::time'

 
 
 

Date and Time stamp to hundredths of seconds?

Post by John Hasle » Sun, 28 Apr 2002 21:21:00


Quote:Paul Rubin writes:
> When I try to run this command, I get the following error:

You're missing libtime-hires-perl.
--
John Hasler

Dancing Horse Hill
Elmwood, Wisconsin
 
 
 

Date and Time stamp to hundredths of seconds?

Post by Dave Bro » Sun, 28 Apr 2002 23:33:12



> Thanks again John,
> When I try to run this command, I get the following error:


> /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503
> /usr/lib/perl5/site_perl/5.005/i386-linux
> /usr/lib/perl5/site_perl/5.005 .) at -e line 1.
> BEGIN failed--compilation aborted at -e line 1.

The "Time::HiRes" is not a standard perl module.  You
have to download it from CPAN and install it.  (And
I believe it requires some compilation, so you when
you go to install, you'll gcc, etc.)

--
Dave Brown  Austin, TX

 
 
 

Date and Time stamp to hundredths of seconds?

Post by John Hasle » Mon, 29 Apr 2002 00:10:52


Quote:Dave Brown writes:
> The "Time::HiRes" is not a standard perl module.  You have to download it
> from CPAN and install it.

If you are running Debian you need only do
'apt-get install libtime-hires-perl'.  I would expect that other
distributions also package perl modules.
--
John Hasler

Dancing Horse Hill
Elmwood, Wisconsin
 
 
 

1. Changing File Modified Time/Date Stamp

Well, maybe I don't know how our sys admin installs it.  :^)FYI, I'm using
Solaris 2.5.1

  > man touch
    ...
  SYNOPSIS
       touch [-acm] [-r ref_file] file...
       touch [-acm] [-t time] file...
       touch [-acm] [date_time] file...

But
  > touch -t 01011200 MyFile
  usage: touch [-amcf] file ...

  > which touch
  /usr/bin/touch

If
  > man -s 1b touch
    ...
  SYNOPSIS
       /usr/ucb/touch [-acfm] file...Obviously, my "touch" command and its
manpage don't match.  :^(

Which is the default "touch" in Solaris 2.5.1?  Where can I  get the "touch"
for Solaris 2.5.1 that allows me to set a specific time/date stamp, as
described in the manpage?

Hon-Chi

2. Specify dir/*/file for -name in find, How to?

3. synchronize date/time stamp with ftp server

4. Problems caused by Numlock (X_GetKeyboardMapping Fails)

5. Calculating deltas between date & time stamps

6. SMC PCI

7. Changing File Modified Time/Date Stamp

8. * Trouble compiling BASH using gcc under Solaris 2.5 x86 *

9. How do you reset file date time stamp

10. time/date stamp via #includes?

11. automatic time/date stamping on compile

12. Calculating deltas between date & time stamps

13. time and date stamp of a file