Created
February 23, 2013 17:14
-
-
Save shigemk2/5020512 to your computer and use it in GitHub Desktop.
DateTimeを使ってみよう
This file contains 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 | |
$t = new DateTime(); | |
print_r($t); | |
/* | |
DateTime Object | |
( | |
[date] => 2013-01-13 14:54:37 | |
[timezone_type] => 3 | |
[timezone] => Asia/Tokyo | |
) | |
*/ | |
print_r($t->format('Y') . PHP_EOL); // 2013 | |
print_r($t->format('m') . PHP_EOL); // 01 | |
print_r($t->format('d') . PHP_EOL); // 13 | |
print_r($t->getTimeStamp() . PHP_EOL); // 1358056477 | |
$subt = $t->sub(new DateInterval('P30D')); | |
print_r($subt); | |
/* | |
DateTime Object | |
( | |
[date] => 2012-12-14 14:55:44 | |
[timezone_type] => 3 | |
[timezone] => Asia/Tokyo | |
) | |
*/ | |
print_r($subt->format('Y/m/d') . PHP_EOL); // 2012/11/14 | |
print_r(date('20130101')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment