Monday, 9 November 2009

timegm() and gmtime()

timegm() is available perl default module Time::Local for converting readable time to its UTC timestamp.

usage:

$epochtime = timegm($sec,$min,$hour,$day,$mon-1,$year-1900)

timegm expects a list of seconds,minutes,hour,day,mon(0..11),year(YYYY) and returns its epochtime

gmtime() does the opposite way:

usage:
($sec,$min,$hour,$day,$mon,$year) = gmtime(1257811200)

returns todays time in a list. $mon will have month from 0 to 11, $year will have 109 (2009-1900). So, $mon+1 will be right month, $year + 1900 will be the current year

No comments:

Post a Comment

Tweets by @sriramperumalla