in reply to Baffled by DateTime
I've tried "DateTime->now(timezone=>"EST5EDT") and it blows up with errors.
Probably because the argument is called time_zone, not timezone?
$ perl -wMstrict -MDateTime -le 'print DateTime->now->strftime("%Y-%m- +%d %H:%M:%S %z")' 2023-03-31 13:08:16 +0000 $ perl -wMstrict -MDateTime -le 'print DateTime->now(time_zone=>"local +")->strftime("%Y-%m-%d %H:%M:%S %z")' 2023-03-31 15:08:23 +0200 $ perl -wMstrict -MDateTime -le 'print DateTime->now(time_zone=>"EST5E +DT")->strftime("%Y-%m-%d %H:%M:%S %z")' 2023-03-31 09:08:29 -0400 $ perl -wMstrict -MDateTime -le 'print DateTime->now(time_zone=>"Ameri +ca/New_York")->strftime("%Y-%m-%d %H:%M:%S %z")' 2023-03-31 09:13:15 -0400 $ perl -wMstrict -MDateTime -le 'print DateTime->now(timezone=>"EST5ED +T")->strftime("%Y-%m-%d %H:%M:%S %z")' Found extra parameters passed to _check_named_from_epoch_params: [time +zone]
Update: In regards to local, see Determining the Local Time Zone Can Be Slow. Also, I would recommend to stay away from ambiguous time zone names like CST ("Central Standard Time", "China Standard Time", "Cuba Standard Time", ...) - correspondingly, I updated my examples above to use %z instead of %Z. Update 2: Added the America/New_York example as an alternative to EST5EDT, as noted on Wikipedia.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Baffled by DateTime
by BernieC (Pilgrim) on Mar 31, 2023 at 13:33 UTC | |
by BernieC (Pilgrim) on Mar 31, 2023 at 15:06 UTC | |
by haukex (Archbishop) on Mar 31, 2023 at 15:35 UTC | |
by hippo (Archbishop) on Mar 31, 2023 at 15:35 UTC | |
by BernieC (Pilgrim) on Mar 31, 2023 at 17:53 UTC | |
by pryrt (Abbot) on Mar 31, 2023 at 18:10 UTC |