PHP calculates the time interval of n days, weeks, months, and years.
- Date_default_timezone_set ('prc'); // Set the time zone
- $ Date1 = strtotime ('1970-01-01 '); // converts a date to a timestamp.
- $ Date2 = time (); // Obtain the timestamp of the current time
- $ Nowtime = strftime ("% Y-% m-% d", $ date2); // format the output date
- $ Days = round ($ date1-$ date2)/3600/24); // rounding
- Echo "today is". $ nowtime ."";
- Echo"
". Strftime (" % Y-% m-% d ", $ date1)." and ". $ days ."
";
- Echo "Current Time". date ("Y-m-d h: I: s", strtotime ("now "))."
";
- Echo "The day After Tomorrow". date ("Y-m-d h: I: s", strtotime ("+ 2 day "))."
";
- Echo "next week". date ("Y-m-d h: I: s", strtotime ("+ 1 week "))."
";
- Echo "next month". date ("Y-m-d h: I: s", strtotime ("+ 1 month "))."
";
- Echo "next year". date ("Y-m-d h: I: s", strtotime ("+ 1 year "))."
";
- Echo "the time after 2 days, 4 hours, and 2 seconds next week ". date ("Y-m-d h: I: s", strtotime ("+ 1 week 2 days 4 hours 2 seconds "))."
";
- Echo "next Thursday". date ("Y-m-d h: I: s", strtotime ("next Thursday "))."
";
- Echo "last week". date ("Y-m-d h: I: s", strtotime ("last Monday "))."
";
- Echo "3 Days Later ". date ("Y-m-d h: I: s", strtotime ("+ 3 day", strtotime ('2017-01-04 ')));
- ?>
|
PHP