Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Convert epoch seconds to date

by belize (Deacon)
on Aug 04, 2001 at 23:58 UTC ( #102262=note: print w/replies, xml ) Need Help??


in reply to Convert epoch seconds to date

How about this subroutine. I'm new to Perl, but think this works OK?:

sub unix_to_date { my ($date) = $_[0]; # reads in variable passed to subroutine my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug sep Oct Nov Dec!; #c +reates array of month names @time = (localtime($date))[3,4,5]; #creates array of date from unix ti +me $time[2] += 1900; # converts year to proper format return "$time[0]-$months[$time[1]]-$time[2]"; }

You now call this with:

$date_from_unix = &unix_to_date(epochtime);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://102262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2019-05-22 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (140 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!