Skip to content

Instantly share code, notes, and snippets.

@homleen
Last active December 17, 2015 16:59
Show Gist options
  • Save homleen/5642377 to your computer and use it in GitHub Desktop.
Save homleen/5642377 to your computer and use it in GitHub Desktop.
Things about date in php.
<?php
// PRC looks like '爬入场';
// Hoho~
date_default_timezone_set('PRC');
var_dump(DateTime::createFromFormat('Ymd', '20130229'));
/*
Result:
object(DateTime)#1 (3) {
["date"]=>
string(19) "2013-03-01 17:24:27"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "PRC"
}
*/
var_dump(stringtotime('20130229');
/*
Result:
int(1362067200)
*/
var_dump(date('Ymd', strtotime('-1 month', strtotime('20130328'))));
/*
Result:
string(8) "20130228"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment