U
U
use_strict2017-02-10 11:10:52
PHP
use_strict, 2017-02-10 11:10:52

How to display dates and times with respect to timezones?

There is an array of strings with dates in the format 2017-02-09T00:20:00+05:00
when using date or datetime, it displays the time excluding +05:00, tell me how to be

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anton_lazarev, 2017-02-10
@use_strict

$date = new DateTime('2017-02-09T00:20:00+05:00');

var_dump($date);

object(DateTime)[367]
  public 'date' => string '2017-02-09 00:20:00.000000' (length=26)
  public 'timezone_type' => int 1
  public 'timezone' => string '+05:00' (length=6)

$date->setTimezone(new DateTimeZone('Europe/Moscow'));

var_dump($date);

object(DateTime)[367]
  public 'date' => string '2017-02-08 22:20:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Moscow' (length=13)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question