kgraff.net - examples

Working with dates - localtime()

script: dates.pl
Last modified 5046.51 days ago, Sat Jul 24 16:30:10 2010

The Perl localtime() function is useful for getting the current system time. It returns a nine element array of values which can then be translated into different formats, such as the YYYY-MM-DD date format used for Oracle and MySQL databases. It is useful for situations where you need to do more than echo variables such as LAST_MODIFIED for modification dates.

Click your Reload or Refresh browser button to see the seconds and minutes update below. If this was your first visit to this page, the welcome message should be replaced by the time stamp for your last visit.

Today is Saturday

The month is May

This is day 138 of the year 2024

The time this statement was executed (24 hour clock): 04:38:39

Todays date in typical database format: 2024-05-18

This convenient time stamp is the result of using: scalar localtime

Sat May 18 04:38:39 2024

A similar Perl function gmtime() returns elements in the standard Greenwich time zone. GMT timestamp:

Sat May 18 11:38:39 2024

For this part to work, your browser must be able to accept cookies. If a cookie has not been set, you get a welcome message. If a cookie from a previous visit is found, the message returned depends on how long ago the visit occurred.

Welcome new visitor!