Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 25th, 2009, 12:06 AM
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Question File time stamp keep printing epoch

Hi,

I'm trying to get a file time stamp to record the file last modifed.
I would like to print as a real time, but I keep getting epoch time instead.

Code:
use Time::Local;

sub getTime
{
   my $filestat = (stat($myfile))[9];
   my $mystamp = scalar(localtime($filestat));

   print "File Stamp " . $mystamp;
}
It's printing "Thu Jan 1 10:00:00 1970"

Can someone tell me what did I do wrong here?

Thanks,
Reply With Quote
  #2 (permalink)  
Old August 25th, 2009, 01:26 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My guess is that you are not passing a valid filename to the sub.
Are you using strict and warnings?

Code:
use strict;
use warnings;
use Time::Local;

sub getTime
{
   my $myfile=shift;
   my $filestat = (stat($myfile))[9];
   my $mystamp = scalar(localtime($filestat));

   print "File Stamp " . $mystamp;
}
getTime("timestamp.pl");
Gives me:
Code:
C:\Temp>perl timestamp.pl
File Stamp Tue Aug 25 15:23:37 2009
But if I remove the 'use strict', 'use warnings' and 'my $myfile=shift' lines, I get the same output as you are getting, because this line:
Code:
my $filestat = (stat($myfile))[9];
has nothing to do a stat() on.
Reply With Quote
  #3 (permalink)  
Old August 30th, 2009, 09:17 PM
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for the reply :)

I found out that it's printing epoch because I have File::stat in my library. :(
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Convert Epoch to YYYYMMDDHHMMSS +GMT skoka123 XSLT 1 September 1st, 2008 11:54 AM
Converting Epoch Time to Readable Date maigoro ASP.NET 3.5 Basics 2 April 12th, 2008 11:42 AM
store insert/update date/time stamp in sql2k db alexdcosta ASP.NET 2.0 Basics 0 June 22nd, 2006 05:44 AM
Inserting Time Stamp into SQL testsubject ADO.NET 1 May 19th, 2006 07:14 AM
Date/Time Stamp on Reports dillig BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 August 11th, 2004 08:21 AM



All times are GMT -4. The time now is 11:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.