#!/usr/bin/perl -w use strict; use Time::Local; #needed for timegm() my $t = '2010-09-06 15:06:53.512999'; #( it is UTC time ) my $newstring = UTC2LocalString($t); print " UTC: $t\n"; print "Local: $newstring\n"; =PRINTS: UTC: 2010-09-06 15:06:53.512999 Local: 2010-09-06 08:06:53.512999 =cut sub UTC2LocalString { my $t = shift; my ($datehour, $rest) = split(/:/,$t,2); my ($year, $month, $day, $hour) = $datehour =~ /(\d+)-(\d\d)-(\d\d)\s+(\d\d)/; # proto: $time = timegm($sec,$min,$hour,$mday,$mon,$year); my $epoch = timegm (0,0,$hour,$day,$month-1,$year); # proto: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = # localtime(time); my ($lyear,$lmonth,$lday,$lhour,$isdst) = (localtime($epoch))[5,4,3,2,-1]; $lyear += 1900; # year is 1900 based $lmonth++; # month number is zero based #print "isdst: $isdst\n"; #debug flag day-light-savings time return ( sprintf("%04d-%02d-%02d %02d:%s", $lyear,$lmonth,$lday,$lhour,$rest) ); }