Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2009, 12:06 AM
Authorized User
 
Join Date: Nov 2007
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,
 
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.
 
Old August 30th, 2009, 09:17 PM
Authorized User
 
Join Date: Nov 2007
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. :(





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.