PHP: DateTime::createFromFormat() with timezone PHP: DateTime::createFromFormat() with timezone php php

PHP: DateTime::createFromFormat() with timezone


(PHP 5 >= 5.3.0)you actually enter the third parameter

public static DateTime DateTime::createFromFormat(string $format , string $time[, DateTimeZone $timezone])

$date = DateTime::createFromFormat('d/m/Y', $date, new DateTimeZone('Europe/Berlin'));


Just use DateTime::setTimeZone():

$date = DateTime::createFromFormat('d/m/Y', $date);$date->setTimeZone(new DateTimeZone('America/New_York'));$date = $date->format('Y-m-d');