strftime format in win32 Perl

C

CesarDBA

Hello to all,

I am trying to execute this peace of code in WindowsXP using
ActiveState Perl 5.8.4:

use POSIX 'strftime';
my($format);
$format = '%r %A %B %d %Y';
print strftime($format, localtime), "\n";
$format = '%I:%M:%S %p %A %B %d %Y';
print strftime($format, localtime), "\n";

This is the result:
Thursday February 09 2006
07:46:01 AM Thursday February 09 2006

The format "%r" is not work. Any thoughts?


Regards.
Antonio Cesar Rosa
 
A

Anno Siegel

CesarDBA said:
Hello to all,

I am trying to execute this peace of code in WindowsXP using
ActiveState Perl 5.8.4:

use POSIX 'strftime';
my($format);
$format = '%r %A %B %d %Y';
print strftime($format, localtime), "\n";
$format = '%I:%M:%S %p %A %B %d %Y';
print strftime($format, localtime), "\n";

This is the result:
Thursday February 09 2006
07:46:01 AM Thursday February 09 2006

The format "%r" is not work. Any thoughts?

The documentation of strftime in "perldoc POSIX" says

If you want your code to be portable, your format
("fmt") argument should use only the conversion
specifiers defined by the ANSI C standard (C89, to
play safe). These are "aAbBcdHIjmMpSUwWxXyYZ%".

So "%r" is not guaranteed to be supported everywhere.

Anno
 
J

Josef Moellers

CesarDBA said:
Hello to all,

I am trying to execute this peace of code in WindowsXP using
ActiveState Perl 5.8.4:

use POSIX 'strftime';
my($format);
$format = '%r %A %B %d %Y';
print strftime($format, localtime), "\n";
$format = '%I:%M:%S %p %A %B %d %Y';
print strftime($format, localtime), "\n";

This is the result:
Thursday February 09 2006
07:46:01 AM Thursday February 09 2006

The format "%r" is not work. Any thoughts?

It's even stranger:
$format = '%r';
will cause "%r" to be printed, while
$format = '%r %A';
causes a blank followed by the weekday to be printed!

Josef
 
J

Josef Moellers

Jim said:
It works under perl 5.8.6 and Posix 1.08 (latest on CPAN is 1.09) under
Mac OS 10.4.4. What versions are you using?

v5.8.6 built for MSWin32-x86-multi-thread

Just for the record: I do not use it. It's just on a Windows box I'm
forced to log into now and then against my will ;-)
 
D

DJB

CesarDBA said:
Hello to all,

I am trying to execute this peace of code in WindowsXP using
ActiveState Perl 5.8.4:

use POSIX 'strftime';
my($format);
$format = '%r %A %B %d %Y';
print strftime($format, localtime), "\n";
$format = '%I:%M:%S %p %A %B %d %Y';
print strftime($format, localtime), "\n";

This is the result:
Thursday February 09 2006
07:46:01 AM Thursday February 09 2006

The format "%r" is not work. Any thoughts?

Supported options on Windows (assuming strftime just uses the system's
underlying strftime() implemenation) can be found here:

http://msdn.microsoft.com/library/d...-us/vclib/html/_crt_strftime.2c_.wcsftime.asp

The closest you can get in a single switch appears to be "%X" or "%#c",
but they don't quite match what you're after.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top