For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > March 2004 > newbie help with Time::Local









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author newbie help with Time::Local
made-man

2004-03-18, 6:46 pm

Hi

I am trying to convert the current date into epoch seconds.

I am experimenting with a simple script that does not seem to work and I do
not see what I am doinf wrong here. Script is as follows :

=======================
use Time::Local;

$time = timelocal($sec);

print "$sec";
=======================

Any advice would be much appreciated.

M


Web Surfer

2004-03-18, 6:46 pm

[This followup was posted to alt.perl]

In article <c102br$1ri$1$8300dec7@news.demon.co.uk>, moe6@lycos.co.uk
says...
> Hi
>
> I am trying to convert the current date into epoch seconds.
>
> I am experimenting with a simple script that does not seem to work and I do
> not see what I am doinf wrong here. Script is as follows :
>
> =======================
> use Time::Local;
>
> $time = timelocal($sec);
>
> print "$sec";
> =======================
>
> Any advice would be much appreciated.
>
> M



You should have a look at the information produced by the command
"perldoc time::local". I have included the first few lines.


NAME
Time::Local - efficiently compute time from local and GMT time

SYNOPSIS
$time = timelocal($sec,$min,$hour,$mday,$mon,$ye
ar);
$time = timegm($sec,$min,$hour,$mday,$mon,$year)
;

DESCRIPTION
These routines are the inverse of built-in perl functions localtime
()
and gmtime(). They accept a date as a six-element array, and return
the
corresponding time(2) value in seconds since the Epoch (Midnight,
January 1, 1970). This value can be positive or negative.
Mina Naguib

2004-03-18, 6:46 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



made-man wrote:
> Hi
>
> I am trying to convert the current date into epoch seconds.
>
> I am experimenting with a simple script that does not seem to work and I do
> not see what I am doinf wrong here. Script is as follows :
>
> =======================
> use Time::Local;
>
> $time = timelocal($sec);
>
> print "$sec";
> =======================


You do not need Time::Local to obtain the current time in epoch seconds.

See `perldoc -f time`

Example:
print time;

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAOuRdeS99pGMif6wRAl5eAJ0VJ/YOQrzbgQpyfSzUWzcJWeHl4wCgpAT4
EHcoaUiz531PPmoQj/cR98Q=
=puqH
-----END PGP SIGNATURE-----
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com