Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: DateTime::createFromFormat() with timezone

I want to convert date form from d/m/Y to Y-m-d with timezone offset. I am able to convert from d/m/Y to Y-m-d with this code:

$date = DateTime::createFromFormat('d/m/Y', $date);
$date = $date->format('Y-m-d');

But I am not sure how to add the timezone offset.

like image 983
yoshi Avatar asked Jun 17 '14 20:06

yoshi


1 Answers

(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'));
like image 80
denoise Avatar answered Sep 20 '22 17:09

denoise