Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created September 7, 2009 04:20
Show Gist options
  • Save kyanny/182145 to your computer and use it in GitHub Desktop.
Save kyanny/182145 to your computer and use it in GitHub Desktop.
#cat dt2.pl
#!/usr/local/bin/perl
use strict;use DateTime;
use DateTime::Format::MySQL;
my $sql_datetime = '2009-09-07 13:15:00';
my $dt1 = DateTime->new(year => 2009, month => 9, day => 7, hour => 13, minute => 15, second => 0);
my $dt2 = DateTime->new(year => 2009, month => 9, day => 7, hour => 13, minute => 15, second => 0, time_zone => 'Asia/Tokyo');
my $dt3 = DateTime::Format::MySQL->parse_datetime($sql_datetime);
print sprintf("datetime = %s, epoch => %s\n", $dt1->datetime, $dt1->epoch);
print sprintf("datetime = %s, epoch => %s\n", $dt2->datetime, $dt2->epoch);
print sprintf("datetime = %s, epoch => %s\n", $dt3->datetime, $dt3->epoch);
my $dt4 = $dt3->clone;$dt4->set_time_zone('Asia/Tokyo');
print sprintf("datetime = %s, epoch => %s\n", $dt4->datetime, $dt4->epoch);
#./dt2.pl
datetime = 2009-09-07T13:15:00, epoch => 1252329300
datetime = 2009-09-07T13:15:00, epoch => 1252296900
datetime = 2009-09-07T13:15:00, epoch => 1252329300
datetime = 2009-09-07T13:15:00, epoch => 1252296900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment