Skip to content

Instantly share code, notes, and snippets.

@satooshi
Last active August 29, 2015 13:56
Show Gist options
  • Save satooshi/9089311 to your computer and use it in GitHub Desktop.
Save satooshi/9089311 to your computer and use it in GitHub Desktop.
! in time format.
<?php
$time = '03/2014';
$dt1 = \DateTime::createFromFormat('m/Y', $time); // "2014-03-19 17:14:38"
$dt2 = \DateTime::createFromFormat('!m/Y', $time); // "2014-03-01 00:00:00"
$dt3 = \DateTime::createFromFormat('m/Y!', $time); // "1970-01-01 00:00:00"
$dt4 = \DateTime::createFromFormat('m!/Y', $time); // "2014-01-01 00:00:00"
var_dump($dt1, $dt2, $dt3, $dt4);
/*
result
object(DateTime)#1 (3) {
["date"]=>
string(19) "2014-03-19 17:14:38"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Asia/Ho_Chi_Minh"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2014-03-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Asia/Ho_Chi_Minh"
}
object(DateTime)#3 (3) {
["date"]=>
string(19) "1970-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Asia/Ho_Chi_Minh"
}
object(DateTime)#4 (3) {
["date"]=>
string(19) "2014-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Asia/Ho_Chi_Minh"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment