php - String to DateTime conversion substracts 1 hour from initial time -


$initialtime = "31.03.2015 17:59"; $timestamp = (new intldateformatter('en_us', intldateformatter::short, intldateformatter::short, 'europe/moscow', intldateformatter::gregorian,'dd.mm.yyyy hh:mm'))->parse($initialtime); $dt = new datetime('@'.$timestamp.' utc'); $dt->settimezone(new datetimezone('europe/moscow'));  var_dump($dt); 

so, $initialtime i'm getting $timestamp using intldateformatter::parse() (timezone 'europe/moscow')

then parse $timestamp datetime , set timezone same, outputs:

class datetime#1 (3) {   public $date =>   string(19) "2015-03-31 16:59:00"   public $timezone_type =>   int(3)   public $timezone =>   string(13) "europe/moscow" } 

why initial time different output time 1 hour?

looks wrond intldateformatter. timestamp datetime object differs parsed one.

$initialdate = new datetime(); $initialdate->settimezone(new datetimezone('europe/moscow')); $initialtime =$initialdate->format('d.m.y h:i'); echo $initialtime, "\n"; echo "real timestamp: ", $initialdate->gettimestamp(), "\n"; $timestamp = (new intldateformatter('ru_ru', intldateformatter::short, intldateformatter::short, 'europe/moscow', intldateformatter::gregorian,'dd.mm.yyyy hh:mm'))->parse($initialtime); echo "parsed timestamp: ", $timestamp, "\n"; 

output:

01.04.2015 16:39 real timestamp:   1427895596 parsed timestamp: 1427891940 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -