Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > dealing with time

Reply
Thread Tools

dealing with time

 
 
Larry
Guest
Posts: n/a
 
      10-26-2008
Hi,

I'm using File::stat to get the last mod time of a file:

my $sb = stat $file;
my $lmod = $sb->mtime;

Now I would like know how many minutes ago (from now) was that file
modified. Can it actually be done?

thanks
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      10-26-2008
Larry schreef:

> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?


for f in stat time; do perldoc -f $f; done

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
 
 
 
Peter Wyzl
Guest
Posts: n/a
 
      10-26-2008
"Larry" <> wrote in message
news:dontmewithme-...
> Hi,
>
> I'm using File::stat to get the last mod time of a file:
>
> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?


Since both time now and time thern are given in seconds (since the epoch
which varies by system), a bit of basic mathematics derives the result.

P

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-26-2008
Larry wrote:
>
> I'm using File::stat to get the last mod time of a file:
>
> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?


my $minutes_last_modified = 1440 * -M $file;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      10-26-2008
In article <AHXMk.8581$>,
"Peter Wyzl" <> wrote:

> Since both time now and time thern are given in seconds (since the epoch
> which varies by system), a bit of basic mathematics derives the result.


in fact I got this:

use File::stat;

my $file = "Mondo.pdf";
my $sb = stat $file;
my $lmod = $sb->mtime;
my $tnow = time;

my $diff = $tnow - $lmod;

Is there anyway to sprintf the $diff value to rappresent: hours, mins,
secs ??

thanks
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      10-26-2008
On 2008-10-26 13:08, John W. Krahn <> wrote:
> Larry wrote:
>> I'm using File::stat to get the last mod time of a file:
>>
>> my $sb = stat $file;
>> my $lmod = $sb->mtime;
>>
>> Now I would like know how many minutes ago (from now) was that file
>> modified. Can it actually be done?

>
> my $minutes_last_modified = 1440 * -M $file;


Nope. -M computes the difference between the modification time and the
time the program was started. There may be a considerable difference
between "when the program was started" and "now".

hp
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      10-26-2008
Larry <> wrote:
>Is there anyway to sprintf the $diff value to rappresent: hours, mins,
>secs ??


Not to make too fine a point but isn't that basic arithmetic at second
grade level?
Of course, there is always Time::Format, too.

jue
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      10-26-2008
In article <>,
J?rgen Exner <> wrote:

> Not to make too fine a point but isn't that basic arithmetic at second
> grade level?


well, I actually am doing the following:

use File::stat;

my $file = "time.pl";
my $sb = stat $file;
my $lmod = $sb->mtime;
my $tnow = time;

my $diff = $tnow - $lmod;

my ($sec,$min,$hour) = (localtime($diff))[0,1,2];

my $time = sprintf( "%1d hr %1d mins %1d secs", $hour - 1, $min, $sec );

Now, I would like to keep showing hours like 25,26 etc... (not days) any
ideas?

thanks
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      10-26-2008
Larry <> wrote:
>In article <>,
> J?rgen Exner <> wrote:
>
>> Not to make too fine a point but isn't that basic arithmetic at second
>> grade level?

>
>Now, I would like to keep showing hours like 25,26 etc... (not days) any
>ideas?


Seconds modulo (60*60)?

jue
 
Reply With Quote
 
Larry
Guest
Posts: n/a
 
      10-26-2008
In article <>,
J?rgen Exner <> wrote:

> Seconds modulo (60*60)?


I really don't get that. What I'm trying to do is:

59 secs

1 min 0 secs

59 min 0 secs

1 hr 0 min 0 secs

24 hr 0 min 0 secs

25 hr 0 min 0 secs
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
Re: interpreting the fractional portion of time.clock() vs time.time(0measurements Peter Hansen Python 0 02-22-2006 02:02 PM
Re: interpreting the fractional portion of time.clock() vs time.time()measurements Peter Hansen Python 0 02-22-2006 12:03 AM
time.clock() or time.time() peterbe@gmail.com Python 8 08-05-2005 01:51 PM
delta time = time stop - time start engsol Python 2 01-26-2004 12:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57