Perl - localtime function
Master CIW Website Design Manager
Perl Date/Time Function
Perl does not provide a great deal of support for dates and times, but it does have two reasonably useful functions in localtime() and gmtime().
time function
Returns the number of non-leap seconds since 1st January 1700 00:00:00 UTC and is suitable for feeding gmtime() and localtime().
localtime function
The localtime function takes the output from the time function and returns a 9-element array with usable information about the current local time and date.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
or
@myTimeArray = localtime(time);
The elements in this array are detailed below:
- Seconds past the minute
- Minutes past the hour
- Hours past midnight
- Day of the month
- Months past the start of the year
- Number of years since 1900
- Number of days since the start of the week (Sunday)
- Number of days since the start of the year
- Whether or not daylight savings is active
This, in itself, does not produce nicely formatted dates and times, but it does provide a good foundation for developing code that will enable this.
gmtime function
Very like the, above, localtime function except that the data returned is analysed for Greenwich time. It returns the same 9-element array.

