phpノートの-時間と日付
2654 ワード
PHP日時の取得現在のUnixタイムスタンプ
PHP日付と時間の取得現在の日付
PHP日時の取得日のUnixタイムスタンプ
PHPは、日付のタイムスタンプを取得するか、時間のタイムスタンプを取得する関数strtotime実装機能を内蔵しています.例:
PHP日付と時刻フォーマットされた日付文字列をUnixタイムスタンプに変換
PHP日付と時間のフォーマットグリニッジ(GMT)標準時間
gmdate関数はGMTの日付と時間をフォーマットすることができ、グリニッジ標準時(GMT)を返します.
1.先月の初日と最終日を取得します. echo date('Y-m-01', strtotime('-1 month')); echo ""; echo date('Y-m-t', strtotime('-1 month')); echo "";2.当月の初日と最終日を取得する. $BeginDate=date('Y-m-01', strtotime(date("Y-m-d"))); echo $BeginDate; echo ""; echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day")); echo "";3.当日の年、月、日及び日数を取得する.echo"今月共有:".date("t").「天」echo「現在の年」.date('Y');echo「現在の月」.date('m');echo「現在の番号」.date('d'); echo "";4.関数および配列を使用して、その月の初日と最終日を取得し、実用的なfunction getthemonth($date){$firstday=date('Y-m-01',strtotime($date);$lastday=date('Y-m-d',strtotime('$firstday+1 month-1 day);return array($firstday,$lastday); } $today = date("Y-m-d"); $day=getthemonth($today);echo「当月の初日:」.$day[0].「当月の最終日:」.$day[1]; echo "";
$time = time();
echo $time;//1396193923, 1970 1 1 00:00:00 1396193923
PHP日付と時間の取得現在の日付
//date ,
echo date("Y-m-d");//2014-03-30
//date ,
echo date("Y-m-d",'1396193923');//2014-03-30,1396193923 2014-03-30 unix
PHP日時の取得日のUnixタイムスタンプ
PHPは、日付のタイムスタンプを取得するか、時間のタイムスタンプを取得する関数strtotime実装機能を内蔵しています.例:
echo strtotime('2014-04-29');//1398700800, 1970 1 1 00:00:00 2014 4 29 1398700800
echo strtotime('2014-04-29 00:00:01');//1398700801, 1970 1 1 00:00:00 2014-04-29 00:00:01 1398700801
, strtotime('2014-04-29') strtotime('2014-04-29 00:00:00')
PHP日付と時刻フォーマットされた日付文字列をUnixタイムスタンプに変換
echo strtotime("now");// now , unix 。 echo time(); 。
echo strtotime("+1 seconds");// 1 , unix 。 echo time()+1; 。
echo strtotime("+1 day");// 1 。
echo strtotime("+1 week");// 1 。
echo strtotime("+1 week 3 days 7 hours 5 seconds");// 1 3 7 5 。
PHP日付と時間のフォーマットグリニッジ(GMT)標準時間
gmdate関数はGMTの日付と時間をフォーマットすることができ、グリニッジ標準時(GMT)を返します.
, , 8 , GMT+8, :
2014-05-01 15:15:22
echo date('Y-m-d H:i:s', time()); // :2014-05-01 15:15:22
echo gmdate('Y-m-d H:i:s', time()); // :2014-05-01 07:15:22 8 , 8
1.先月の初日と最終日を取得します. echo date('Y-m-01', strtotime('-1 month')); echo ""; echo date('Y-m-t', strtotime('-1 month')); echo "";2.当月の初日と最終日を取得する. $BeginDate=date('Y-m-01', strtotime(date("Y-m-d"))); echo $BeginDate; echo ""; echo date('Y-m-d', strtotime("$BeginDate +1 month -1 day")); echo "";3.当日の年、月、日及び日数を取得する.echo"今月共有:".date("t").「天」echo「現在の年」.date('Y');echo「現在の月」.date('m');echo「現在の番号」.date('d'); echo "";4.関数および配列を使用して、その月の初日と最終日を取得し、実用的なfunction getthemonth($date){$firstday=date('Y-m-01',strtotime($date);$lastday=date('Y-m-d',strtotime('$firstday+1 month-1 day);return array($firstday,$lastday); } $today = date("Y-m-d"); $day=getthemonth($today);echo「当月の初日:」.$day[0].「当月の最終日:」.$day[1]; echo "";