How to retrieve utc time for amazon ses requests?
My requests to the amazon ses is reporting GMT expired. Some people told me to use UTC date format in the requests to amazon and use sincronized time.
the code is in perl and the line is:
$params{'Timestamp'} = sprintf("%04d-%02d-%02dT%02d:%02d:%02d.000Z",sub {($_[5]+1900,$_[4]+1,$_[3],$_[2],$_[1],$_[0])}->(gmtime(time)));
The question is... i want this in u开发者_StackOverflow社区tc format but i dont know at all perl language =s
Whenever I see +1900
in code I cringe, because there is generally no need to do such low-level datetime calculations manually. Instead use libraries like DateTime to do all the calculations and formatting for you:
use DateTime;
use Time::HiRes 'time';
my $dt = DateTime->from_epoch(epoch => time, time_zone => 'UTC');
my $timestamp_string = $dt->strftime('%FT%T.%3NZ');
produces: 2011-02-02T18:37:03.145Z
PS. if you are having difficulty synchronizing your server to Amazon, your clock has probably drifted. You should install a service like ntpd to keep your clock synchronized - see serverfault.com if you have difficulty.
精彩评论