Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Question regarding Time::Piece and timezones

by parv (Parson)
on Jan 14, 2021 at 06:11 UTC ( [id://11126887]=note: print w/replies, xml ) Need Help??


in reply to Question regarding Time::Piece and timezones

The string time zone seems to be an issue ...

#!perl use warnings; use strict; use Carp; use Time::Piece; $SIG{__WARN__} = sub { Carp::cluck @_; }; $SIG{__DIE__} = sub { Carp::confess @_; }; $| = 1; my $format_notz = "%a, %d %b %Y %T"; my $format_tz_name = "${format_notz} %Z"; my $format_tz_offset = "${format_notz} %z"; my $time = 'Wed, 13 Jan 2021 17:00:00'; my %time_map = ( $time => $format_notz, qq[$time CST] => $format_tz_name, qq[$time -0600] => $format_tz_offset, ); for my $t ( sort keys %time_map ) { my $format = $time_map{ $t }; my $tp = Time::Piece->strptime( $t, $format ); printf "%s\n -> %s ->\n", $t, $format; printf " %s\n\n", $tp->strftime( $format ); } __END__ Wed, 13 Jan 2021 17:00:00 -> %a, %d %b %Y %T -> Wed, 13 Jan 2021 17:00:00 Wed, 13 Jan 2021 17:00:00 -0600 -> %a, %d %b %Y %T %z -> Wed, 13 Jan 2021 23:00:00 +0000 Error parsing time at C:/Users/parv/mine--no-backup/strawberry-perl-5. +32.0.1-64bit-portable/perl/lib/Time/Piece.pm line 598. at x-timepc.pl line 9. main::__ANON__("Error parsing time at C:/Users/parv/mine--no-b +ackup/strawberr"...) called at C:/Users/parv/mine--no-backup/strawber +ry-perl-5.32.0.1-64bit-portable/perl/lib/Time/Piece.pm line 598 Time::Piece::strptime("Time::Piece", "Wed, 13 Jan 2021 17:00:0 +0 CST", "%a, %d %b %Y %T %Z") called at x-timepc.pl line 26

FreeBSD man strftime.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11126887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-18 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found