DelphiFAQ Home Search:

Obtaining the time and time in different formats


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The localtime function is described in the perlfunc.pod as: "[converting] a time as returned by the time function to a 9-element array with the time analyzed for the local time zone." It returns different values, depending on whether it is called in list or scalar context.

Using it as an argument to the print function, which takes its arguments in list context, returns an array of values. Therefore, it is similar to printing an array or list. You will get a concatenated string of numbers as each element of print's argument list is stringified before printing. (You can use the join function to separate the values. See example with next paragraph.)

Assigning the result of the function to a scalar, or forcing scalar context with the scalar operator, will return a date/time string. Similarly, using the substr() function (to get a substring) is also scalar context. The line containing 'substr' below gets the 1st 3 chars of localtime's scalar context returned string:

print localtime();                       # returns 1319121089952521
print join (" ",localtime() );           # returns 13 19 12 10 8 99 5 252 1
print scalar localtime();                # returns Fri Sep 10 12:19:13 1999
$datetime = localtime();                 # assignment is scalar context
print $datetime;                         # returns Fri Sep 10 12:19:13 1999

Content-type: text/html


2012-11-12, 02:56:55
anonymous from United Kingdom  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: