Last active
May 29, 2016 04:27
-
-
Save nishinoshake/6433fdefa8dd5e0973cc to your computer and use it in GitHub Desktop.
時刻関連のすべて
This file contains hidden or 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
//現在の日付を取得する,第2引数を省略するとtime()が初期値 | |
$date = date("Y/m/d H:i:s"); | |
Y 2016 y 16 | |
m 09 n 9 | |
d 07 j 7 | |
I Monday D Mon w 1(曜日番号,0~6) | |
H 14 h 02 (hour) | |
i 18 (minutes) | |
s 07 (second) | |
//比較するときはUNIXタイムに変換してから | |
//一週間以内の比較 | |
if ( strtotime($date) >= strtotime('-7 day') ) { | |
// do something | |
} |
This file contains hidden or 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
// 現在のUNIXタイムを取得する | |
$time = time(); | |
//指定した時間のUNIXタイム | |
//絶対日時 | |
$time = strtotime( '2014/1/1 10:20:30' ) ; | |
//相対日時 第2引数を省略したらtime() | |
$time = strtotime( "+4 day" ) ; | |
//今日の0時から4日後のUNIXタイム | |
$timestamp = strtotime( "+4 day" , strtotime( date("Y/m/d 00:00:00") ) ) ; | |
+1 year / +1 month / -1 week / +1 day / -1 hour / +1 minute / -1 second |
This file contains hidden or 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
//日本語で曜日を出力する | |
echo array( '日' , '月' , '火' , '水' , '木' , '金' , '土' )[date('w')]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment