POSIX::strftime::Compiler3pm
Gnu c library compatible strftime for loggers and servers
Usage
use POSIX::strftime::Compiler qw/strftime/;say strftime('%a, %d %b %Y %T %z',localtime):my $fmt = '%a, %d %b %Y %T %z';my $psc = POSIX::strftime::Compiler->new($fmt);say $psc->to_string(localtime);
Overview
POSIX::strftime::Compiler provides GNU C library compatible strftime(3). But this module will not affected by the system locale. This feature is useful when you want to write loggers, servers and portable applications.
For generate same result strings on any locale, POSIX::strftime::Compiler wraps POSIX::strftime and converts some format characters to perl code
Function
- strftime($fmt:String, @time)
-
Generate formatted string from a format and time.
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();strftime('%d/%b/%Y:%T %z',$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst):Compiled codes are stored in
%POSIX::strftime::Compiler::STRFTIME. This function is not exported by default.
Methods
new($fmt)
|
create instance of POSIX::strftime::Compiler |
|---|---|
to_string(@time)
|
Generate formatted string from time. |
Format characters
POSIX::strftime::Compiler supports almost all characters that GNU strftime(3) supports. But %E[cCxXyY] and %O[deHImMSuUVwWy] are not supported, just remove E and O prefix.
A recommend module
- Time::TZOffset
-
If Time::TZOffset is available, P::s::Compiler use it for more faster time zone offset calculation. I strongly recommend you to install this if you use
%z.
Performance issues on windows
Windows and Cygwin and some system may not support %z and %Z. For these system, POSIX::strftime::Compiler calculate time zone offset and find zone name. This is not fast. If you need performance on Windows and Cygwin, please install Time::TZOffset
Releases
6 releases since Debian 8 (Jessie); the text changed 4 times.