CIW Course Revision Site


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:

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.

Design by Stephen

Certified Internet Webmaster

Page last Edited: 10 Nov 2011