timestamp with milisecond

Hi List
Is it possible to get the current time_stamp with milisecond format

like HH:MI:SS:NNN DD:MM:YYYY(NNN is the milisecond)

If yes then how can I achieve the same..............

Thanks & Regards in advance
Anirban Adhikary.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Anirban Adhikary [ Fr, 03 Juni 2011 09:38 ] [ ID #2060471 ]

Re: timestamp with milisecond

--001636831fa8b0791404a4c9de91
Content-Type: text/plain; charset=UTF-8

On Fri, Jun 3, 2011 at 9:38 AM, Anirban Adhikary <anirban.adhikary [at] gmail.com
> wrote:

> Hi List
> Is it possible to get the current time_stamp with milisecond format
>
> like HH:MI:SS:NNN DD:MM:YYYY(NNN is the milisecond)
>
> If yes then how can I achieve the same..............
>
> Thanks & Regards in advance
> Anirban Adhikary.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>
Hi Anirban,

Sure you can have a look at the following CPAN module:
http://search.cpan.org/dist/Time-HiRes/HiRes.pm

It will do exactly what you are looking for.

Regards,

Rob

--001636831fa8b0791404a4c9de91--
Rob Coops [ Fr, 03 Juni 2011 09:40 ] [ ID #2060472 ]

Re: timestamp with milisecond

Posting in some childish perl........please bear it


1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Time::HiRes qw(gettimeofday);
5 use Time::Local;
6 use Time::localtime;
7
8 my $t0 = gettimeofday;
9
10 my $forlocaltime = int($t0);
11 my $for_millisecond = int(($t0-$forlocaltime)*1000);
12
13 my $tm = localtime($forlocaltime);
14
15 printf ("Current Time- %02d:%02d:%02d:%03d %02d/%02d/%02d\n", $tm->hour, $tm ->min,$tm->sec,$for_millisecond, $tm->mday, $tm->mon+1, $tm->year+1900);


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Gurpreet Singh [ Fr, 03 Juni 2011 13:46 ] [ ID #2060496 ]

Re: timestamp with milisecond

Me too a beginner, posting a reply in childish speech:



1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Time::HiRes qw(gettimeofday);
5 use Time::Local;
6 use Time::localtime;
7
8 my $t0 = gettimeofday;
9
10 my $forlocaltime = int($t0);
11 my $for_millisecond = int(($t0-$forlocaltime)*1000);
12
13
14 my $tm = localtime($forlocaltime);
15
16 printf ("Current Time- %02d:%02d:%02d:%03d %02d/%02d/%02d\n", $tm->hour, $tm ->min,$tm->sec,$for_millisecond, $tm->mday, $tm->mon+1, $tm->year+1900);



Output -
Current Time- 17:09:04:312 03/06/2011
Current Time- 17:09:08:140 03/06/2011


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Gurpreet Singh [ Fr, 03 Juni 2011 13:42 ] [ ID #2060497 ]

Re: timestamp with milisecond

>>>>> "GS" == Gurpreet Singh <gurpreetsingh13 [at] khalsa.com> writes:

GS> Posting in some childish perl........please bear it

please don't post with line numbers. that makes it very hard to
cut/paste your code to try it out.

GS> 1 #!/usr/bin/perl
GS> 2 use warnings;
GS> 3 use strict;
GS> 4 use Time::HiRes qw(gettimeofday);
GS> 5 use Time::Local;
GS> 6 use Time::localtime;
GS> 7
GS> 8 my $t0 = gettimeofday;
GS> 9
GS> 10 my $forlocaltime = int($t0);
GS> 11 my $for_millisecond = int(($t0-$forlocaltime)*1000);
GS> 12
GS> 13 my $tm = localtime($forlocaltime);
GS> 14
GS> 15 printf ("Current Time- %02d:%02d:%02d:%03d %02d/%02d/%02d\n", $tm->hour, $tm ->min,$tm->sec,$for_millisecond, $tm->mday, $tm->mon+1, $tm->year+1900);

regardless of the need for millisecond info, use the POSIX::strftime
function as it does all of that formatting timestamps for you. and since
you pass it a string you can just interpolate the millisecond part into
that string.

uri

--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Uri Guttman [ Sa, 04 Juni 2011 01:47 ] [ ID #2060499 ]

Re: timestamp with milisecond

On Fri, 03 Jun 2011 19:47:53 -0400, Uri Guttman wrote:
> regardless of the need for millisecond info, use the POSIX::strftime
> function as it does all of that formatting timestamps for you. and sinc=
e
> you pass it a string you can just interpolate the millisecond part into
> that string.

Like so:

$ perl -MPOSIX=3Dstrftime -MTime::HiRes=3Dtime -le '$t =3D time; $s=3Dspr=
intf "%
06.3f", $t-int($t/60)*60; print strftime "%H:%M:$s %d:%m:%Y", localtime
$t'
20:38:44.551 03:06:2011

--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/courses/perl3/

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Peter Scott [ Sa, 04 Juni 2011 05:40 ] [ ID #2060503 ]
Perl » gmane.comp.lang.perl.beginners » timestamp with milisecond

Vorheriges Thema: issue with a multidimensional hash .. unable recreate the desired hash
Nächstes Thema: Using $variable outside a foreach loop