Created
February 19, 2015 15:20
-
-
Save zemd/0c0dfb5a5733a6ba279b to your computer and use it in GitHub Desktop.
working with \DateTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('UTC'); | |
$micro = explode(" ", microtime()); | |
$micros = substr($micro[0], 1, 7); | |
$date = date('Y-m-d H:m:i'); | |
$dtString = $date . $micros; | |
$datetime = DateTime::createFromFormat('Y-m-d H:m:i.u', $dtString, new DateTimeZone('UTC')); | |
$datetime2 = new DateTime($dtString, new DateTimeZone('UTC')); | |
$datetime3 = new DateTime("now", new DateTimeZone('UTC')); | |
var_dump($datetime3->format('Uu')); | |
var_dump($datetime2->format('Uu')); | |
var_dump($dtString); | |
var_dump($datetime->format('Uu')); | |
//var_dump(DateTime::getLastErrors()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment