POSIX:...ompiler(3pm)
π NAME
POSIX::strftime::Compiler β GNU C library compatible strftime for loggers and servers π
(also hi, you're reading the POSIX:...ompiler page from the User Contributed Perl Documentation, welcome bestie πΈ)
β¨ SYNOPSIS
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);
π¦ DESCRIPTION
So POSIX::strftime::Compiler gives you a GNU C library compatible strftime(3). But here's the slay part: this module will not be affected by the system locale π. That's literally the whole point β it's so useful when you want to write loggers, servers, and portable applications.
To generate the same result strings on any locale, POSIX::strftime::Compiler wraps POSIX::strftime and converts some format characters to perl code. Iconic behavior, no cap π
π₯ FUNCTION
strftime($fmt:String, @time)
Generate a formatted string from a format and a time. That's it, that's the vibe β¨
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):
Heads up bestie π«Ά: compiled codes are stored in %POSIX::strftime::Compiler::STRFTIME. Also this function is not exported by default β you gotta ask for it.
π§ METHODS
new($fmt)
Creates an instance of POSIX::strftime::Compiler. Main character energy π
to_string(@time)
Generate a formatted string from a time. Go off, honestly π
π FORMAT CHARACTERS
POSIX::strftime::Compiler supports almost all the characters that GNU strftime(3) supports π But β and this is the catch β %E[cCxXyY] and %O[deHImMSuUVwWy] are not supported. Just remove the E and O prefix, that's the whole workaround π
π A RECOMMEND MODULE
Time::TZOffsetβ ifTime::TZOffsetis available,P::s::Compileruses it for a more faster time zone offset calculation β‘ I strongly recommend you install this if you use%z.
π PERFORMANCE ISSUES ON WINDOWS
Windows and Cygwin and some systems may not support %z and %Z π For these systems, POSIX::strftime::Compiler calculates the time zone offset and finds the zone name. This is not fast β like, not me waiting π If you need performance on Windows and Cygwin, please install Time::TZOffset.
π SEE ALSO
POSIX::strftime::GNUβPOSIX::strftime::Compileris built onPOSIX::strftime::GNU::PPcodePOSIXApache::LogFormat::Compiler
π LICENSE
Copyright (C) Masahiro Nagano.
Format specification is based on the strftime(3) manual page which is a part of the Linux man-pages project.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Periodt π«Ά
β AUTHOR
Masahiro Nagano <kazeburo@gmail.com>
okay bye bestie, go format some timestamps π
β¨π¦ β this was perl v5.42.0, dated 2024-03-08, from the POSIX:...ompiler(3pm) page. mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-POSIX-strftime-Compiler 0.460.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms