- COPYRIGHT AND LICENSE
- SEE ALSO
Time::FFI - libffi interface to POSIX date and time functions
use Time::FFI qw(localtime mktime strptime strftime); my $tm = strptime '1995-01-02 13:15:39', '%Y-%m-%d %H:%M:%S'; my $epoch = mktime $tm; print "$epoch: ", strftime('%I:%M:%S %p on %B %e, %Y', $tm); my $piece = $tm->to_object('Time::Piece', 1); my $tm = localtime time; my $datetime = $tm->to_object('DateTime', 1); my $tm = gmtime time; my $moment = $tm->to_object('Time::Moment', 0);
Time::FFI provides a libffi interface to POSIX date and time functions found in time.h.
The "gmtime" and "localtime" functions behave very differently from the core functions of the same name, as well as those exported by Time::Piece, so you may wish to call them as e.g.
Time::FFI::gmtime rather than importing them.
All functions will throw an exception in the event of an error. For functions other than "strftime" and "strptime", this exception will contain the syscall error message, and "$!" in perlvar will also have been set by the syscall, so you could check it after trapping the exception for finer exception handling.
All functions are exported individually, or with the
:all export tag.
my $str = asctime $tm;
my $str = ctime $epoch; my $str = ctime;
Returns a string in the format
Wed Jun 30 21:49:08 1993\n representing the passed epoch timestamp (defaulting to the current time) in the local time zone. This is equivalent to "ctime" in POSIX but uses the thread-safe ctime_r(3) function if available.
my $tm = gmtime $epoch; my $tm = gmtime;
my $tm = localtime $epoch; my $tm = localtime;
my $epoch = mktime $tm;
Returns the epoch timestamp representing the passed Time::FFI::tm record interpreted in the local time zone.
my $str = strftime $format, $tm;
my $tm = strptime $str, $format; $tm = strptime $str, $format, $tm; my $tm = strptime $str, $format, undef, \my $remaining; $tm = strptime $str, $format, $tm, \my $remaining;
A Time::FFI::tm record may be passed as the third argument, in which case it will be modified in place to (on most systems) update only the date/time elements which were parsed from the string. Additionally, an optional scalar reference may be passed as the fourth argument, in which case it will be set to the remaining unprocessed characters of the input string if any.
This function is usually not available on Windows.
Report any issues on the public bugtracker.
Dan Book <email@example.com>
This software is Copyright (c) 2019 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)