Skip to content

Instantly share code, notes, and snippets.

@hamakn
Created March 15, 2013 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamakn/5168436 to your computer and use it in GitHub Desktop.
Save hamakn/5168436 to your computer and use it in GitHub Desktop.
use 5.016;
use DateTime;
# beginning_of_day
say DateTime->now( time_zone=>'local' )->truncate( to => "day" )->strftime('%Y/%m/%d %H:%M:%S')
# => 2013/03/15 00:00:00
# サマータイムで存在しない時刻を指定すると例外
# (America/Chicago時刻では、2003-04-06 01:59:59 の次は 2003-04-06 03:00:00)
DateTime->new( time_zone => 'America/Chicago', year => 2003, month => 4, day => 6, hour => 2, minute => 0, second => 0 );
# => Invalid local time for date in time zone: America/Chicago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment