Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 23, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/5020512 to your computer and use it in GitHub Desktop.
Save shigemk2/5020512 to your computer and use it in GitHub Desktop.
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
print_r(date('20130101'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment