In PHP
We have made the time there are many ways
But to get sometime time
We need more special description
Example
<?php //Obtain UNIX time echo(strtotime("now")).'<br>';//Right now echo(strtotime("3 October 2005")).'<br>';//2005-10-3 echo(strtotime("+5 hours")).'<br>';//Now After 5 hours echo(strtotime("+1 week")).'<br>';//Now after a week echo(strtotime("+1 week 3 days 7 hours 5 seconds")).'<br>';//Now seven hours three days a week for 5 seconds echo(strtotime("next Monday")).'<br>';//Next Monday echo(strtotime("last Sunday")).'<br>';//Last Sunday echo(strtotime("next Month")).'<br>';//Next month ?>
So with the date() function
<?php echo 'right now is'.date('Y-m-d H:i:s',strtotime("now")).'<br>'; echo '2005-10-3 is'.date('Y-m-d H:i:s',strtotime("3 October 2005")).'<br>'; echo 'after 5 hours is '.date(' Y-m-d H:i:s',strtotime("+5 hours")).'<br>'; echo 'after one week is '.date(' Y-m-d H:i:s',strtotime("+1 week")).'<br>'; echo 'after 1 week 3 days 7 hours 5 seconds is '.date('Y-m-d H:i:s',strtotime("+1 week 3 days 7 hours 5 seconds")).'<br>'; echo 'next Monday is '.date('Y-m-d H:i:s',strtotime("next Monday")).'<br>'; echo 'last Sunday is '.date('Y-m-d H:i:s',strtotime("last Sunday")).'<br>'; echo 'next Month is '.date('Y-m-d H:i:s',strtotime("next Month")).'<br>'; ?>
So it is very simple
Official website has more detailed instructions
Description | Format |
---|---|
dayname | 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' |
daytext | 'weekday' | 'weekdays' |
number | [+-]?[0-9]+ |
ordinal | 'first' | 'second' | 'third' | 'fourth' | 'fifth' | 'sixth' | 'seventh' | 'eighth' | 'ninth' | 'tenth' | 'eleventh' | 'twelfth' | 'next' | 'last' | 'previous' | 'this' |
reltext | 'next' | 'last' | 'previous' | 'this' |
space | [ \t]+ |
unit | (('sec' | 'second' | 'min' | 'minute' | 'hour' | 'day' | 'fortnight' | 'forthnight' | 'month' | 'year') 's'?) | 'weeks' |daytext |
Format | Description | Examples |
---|---|---|
'yesterday' | Midnight of yesterday | "yesterday 14:00" |
'midnight' | The time is set to 00:00:00 | |
'today' | The time is set to 00:00:00 | |
'now' | Now - this is simply ignored | |
'noon' | The time is set to 12:00:00 | "yesterday noon" |
'tomorrow' | Midnight of tomorrow | |
'back of'hour | 15 minutes past the specified hour | "back of 7pm", "back of 15" |
'front of'hour | 15 minutes before the specified hour | "front of 5am", "front of 23" |
'first day of' | Sets the day of the first of the current month. This phrase is best used together with a month name following it. | "first day of January 2008" |
'last day of' | Sets the day to the last day of the current month. This phrase is best used together with a month name following it. | "last day of next month" |
ordinalspacedaynamespace'of' | Calculates thex-th week day of the current month. | "first sat of July 2008" |
'last'spacedaynamespace'of' | Calculates thelastweek day of the current month. | "last sat of July 2008" |
numberspace? (unit| 'week') | Handles relative time items where the value is a number. | "+5 weeks", "12 day", "-7 weekdays" |
ordinalspaceunit | Handles relative time items where the value is text. | "fifth day", "second month" |
'ago' | Negates all the values of previously found relative time items. | "2 days ago", "8 days ago 14:00", "2 months 5 days ago", "2 months ago 5 days", "2 days ago" |
dayname | Moves to the next day of this name. | "Monday" |
reltextspace'week' | Handles the special format "weekday + last/this/next week". | "Monday next week" |
Oh, If still have questions to ask
Thanksgiving!
Thanksgiving!
Message Board
Feel free to leave suggestions and share! Thanksgiving!