by shigemk2

当面は技術的なことしか書かない

DateTime型のいろいろなおさらい

<?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

PHP: DateTime - Manual