Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Конвертация времени через date_timestamp_get
Форумы портала PHP.SU » » Вопросы новичков » Конвертация времени через date_timestamp_get

Страниц (1): [1]
 

1. Corvus87 - 08 Октября, 2017 - 21:10:13 - перейти к сообщению
Новичок, так что не сильно позорьте ))

При конвертации через date_timestamp_get теряется один час. Если на входе задать "2015-05-15 00:00:00+00" после конвертации через date_timestamp_get получаю временную метку равную "2015-05-14 23:00:00+00", то есть минус один час. Где здесь может быть ошибка?

$date_start = "2015-05-15 00:00:00+00";
$date_timestamp = \DateTime::createFromFormat('Y-m-d H:i:s+', $date_start);
$date_timestamp = date_timestamp_get($date_timestamp); // "2015-05-14 23:00:00+00"
2. andrewkard - 09 Октября, 2017 - 09:10:46 - перейти к сообщению
не тот пример выдрал
PHP:
скопировать код в буфер обмена
  1.  
  2. Note that getTimestamp() does not return the UTC timestamp. It returns the timestamp relative to the set timezone, or the default server timezone. This also applies to dates in timezones with Daylight Savings.
  3.  
  4. <?PHP
  5. // 11th March 2016 @ 11:00 UTC has timestamp: 1457694000
  6. $d1 = new DateTime('2016-03-11 11:00:00', new DateTimeZone('Europe/Rome'));
  7. $t1 = $d1->getTimestamp();
  8.  
  9. // 11th April 2016 @ 11:00 UTC has timestamp: 1460372400
  10. $d2 = new DateTime('2016-04-11 11:00:00', new DateTimeZone('Europe/Rome'));
  11. $t2 = $d2->getTimestamp();
  12.  
  13. printf("11 March: %d (diff = %d less)\n", $t1, 1457694000 - $t1);
  14. printf("11 April: %d (diff = %d less)", $t2, 1460372400 - $t2);
  15.  
  16. // Prints:
  17. // 1457690400 (diff = 3600)
  18. // 1460365200 (diff = 7200)
  19.  
3. Corvus87 - 09 Октября, 2017 - 22:44:39 - перейти к сообщению
andrewkard пишет:
не тот пример выдрал
PHP:
скопировать код в буфер обмена
  1.  
  2. Note that getTimestamp() does not return the UTC timestamp. It returns the timestamp relative to the set timezone, or the default server timezone. This also applies to dates in timezones with Daylight Savings.
  3.  
  4. <?PHP
  5. // 11th March 2016 @ 11:00 UTC has timestamp: 1457694000
  6. $d1 = new DateTime('2016-03-11 11:00:00', new DateTimeZone('Europe/Rome'));
  7. $t1 = $d1->getTimestamp();
  8.  
  9. // 11th April 2016 @ 11:00 UTC has timestamp: 1460372400
  10. $d2 = new DateTime('2016-04-11 11:00:00', new DateTimeZone('Europe/Rome'));
  11. $t2 = $d2->getTimestamp();
  12.  
  13. printf("11 March: %d (diff = %d less)\n", $t1, 1457694000 - $t1);
  14. printf("11 April: %d (diff = %d less)", $t2, 1460372400 - $t2);
  15.  
  16. // Prints:
  17. // 1457690400 (diff = 3600)
  18. // 1460365200 (diff = 7200)
  19.  


Ok, спасибо

 

Powered by ExBB FM 1.0 RC1