Click here to get back home

How to print formatted (!) the current timestamp?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to print formatted (!) the current timestamp? Thomas Blabb 05-04-2008
Posted by Thomas Blabb on May 4, 2008, 5:09 am
Please log in for more thread options
I want to print the current time(stamp) in formatted style.
The following does not work:

print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time);

What is wrong?

How else can I print out a formatted timestamp?

Tom


Posted by Owen on May 4, 2008, 6:03 am
Please log in for more thread options
On May 4, 7:09 pm, t.bl...@gmail.com (Thomas Blabb) wrote:
> I want to print the current time(stamp) in formatted style.
> The following does not work:
>
> print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time);
>
> What is wrong?
>
> How else can I print out a formatted timestamp?
>
> Tom

Try

use POSIX qw(strftime);
print strftime "%Y%m%d-%H%M\n", localtime;


Owen

Posted by Keith Keller on May 4, 2008, 2:06 pm
Please log in for more thread options
> I want to print the current time(stamp) in formatted style.
> The following does not work:
>
> print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time);

Did you read perldoc -f localtime?

If you are happy with localtime's formatting, simply print it as a
scalar:

print scalar localtime();

If you want to use a print-equivalent statement to do your formatting,
you need to use printf. Also, perl date formatting has nothing to do
with UNIX date; %Y for example is the hash named Y, and bears no
relation at all to your call to localtime. Read perldoc -f sprintf for
valid formats (%Y is certainly not one).

--keith

--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information


Posted by Gunnar Hjalmarsson on May 4, 2008, 2:22 pm
Please log in for more thread options
Keith Keller wrote:
> perl date formatting has nothing to do with UNIX date; %Y for example
> is the hash named Y, and bears no relation at all to your call to
> localtime. Read perldoc -f sprintf for valid formats (%Y is
> certainly not one).

Wouldn't it have been better to point the OP to POSIX::strftime() and
drop that rant?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Keith Keller on May 4, 2008, 4:54 pm
Please log in for more thread options
> Keith Keller wrote:
>> perl date formatting has nothing to do with UNIX date; %Y for example
>> is the hash named Y, and bears no relation at all to your call to
>> localtime. Read perldoc -f sprintf for valid formats (%Y is
>> certainly not one).
>
> Wouldn't it have been better to point the OP to POSIX::strftime() and
> drop that rant?

Was I ranting? I thought I was just being complete. Thanks for the
pointer to POSIX::strftime; I seldom use the POSIX:: modules.

--keith

--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information


Similar ThreadsPosted
print all current variables May 2, 2005, 8:23 pm
Returning to beginning of current line with print()? October 18, 2006, 11:51 pm
Formatted printing June 14, 2005, 11:12 am
Reading a ctime formatted date April 24, 2007, 1:46 pm
strings with formatted characters in %ARGV June 25, 2007, 12:33 pm
How to force formatted date (month) language ? July 7, 2006, 6:02 pm
reading in a nested formatted data structure with quirks June 28, 2006, 6:15 pm
(",) Print This! Press [Ctrl][P] Keys To Print... >> http://www.phpbbserver.com/phpbb/viewtopic.php?t=2&mforum=anysubjectchat < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < May 30, 2005, 2:05 pm
Preserve Timestamp January 21, 2005, 1:34 pm
FAQ 5.23: How do I get a file's timestamp in perl? December 19, 2004, 12:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap