Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Use 'localtime' or 'gmtime'. 'localtime' returns local time information and 'gmtime' returns time based on GMT time zone.

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

Both functions expects as parameter the number of seconds since the epoch (00:00 January 1, 1970 for most systems, 00:00 January 1, 1904 for MacOS). That value is returned by the 'time' function.

The functions returns a 9-element list with the following structure:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)

All the elements are numeric, the meaning of the elements are the following:

  • $sec, $min, $hour - seconds, minutes and hours of the specified time
  • '$mday' - day of the month (1..31)
  • '$mon' - month number, ranging from 0 (January) to 11 (December)
  • $year - number of years since 1900
  • $wday - day of the week, ranging from 0 (Sunday) to 6 (Saturday)
  • $yday - day of the year, ranging from 0 to 364 (or 365 in leap years)
  • $isdst - true if the specified time is within daylight savings time, false otherwise