Page 513 - Beginning PHP 5.3
P. 513

Chapter 16: PHP and the Outside World

                                Date/Time String               Meaning
                                  tomorrow 1:30pm                The day after the current date at 1:30 pm
                                  Today                        Midnight on the current date

                                  Yesterday                      Midnight on the day before the current date
                                  last Thursday                  Midnight on the Thursday before the current date

                                  +2 days                        The day after tomorrow at the current time of day
                                   - 1 year                      One year ago at the current time of day
                                  +3 weeks 4 days 2 hours           3 weeks, 4 days, and 2 hours from now

                                  3 days                         3 days after the current date at the current time
                                  4 days ago                     4 days before the current date at the current time
                                  3 hours 15 minutes             The current time plus 3 hours 15 minutes


                           As with  mktime() ,  strtotime()  assumes by default that the string you pass it represents a date and
                          time in the computer ’ s time zone, and converts to UTC accordingly. However, you can specify a time in
                          a different time zone by adding an offset from UTC, using a plus or minus sign followed by a four - digit
                          number at the end of the string. The first two digits represent the hours component of the offset, and the
                          second two digits represent the minutes. For example:
                             $t = strtotime( “February 15th 2004, 9:30am +0000” ); // GMT
                             $t = strtotime( “February 15th 2004, 9:30am +0100” ); // 1 hour ahead of GMT
                             $t = strtotime( “February 15th 2004, 9:30am -0500” ); // Indianapolis time
                             $t = strtotime( “February 15th 2004, 9:30am +1000” ); // Sydney time (not DST)

                             $t = strtotime( “February 15th 2004, 9:30am +1100” ); // Sydney time (with DST)
                            strtotime()  calculates relative dates (such as  “ tomorrow 1:30pm ” ) based on the current date. If you
                          want to calculate a relative date based on a different date, pass that date as a second argument to
                            strtotime() , in timestamp format:



                             $localTime = strtotime( “tomorrow 1:30pm”, 0 ); // January 2nd 1970, 1:30:00 pm
                           Extracting Date and Time Values from a Timestamp
                           Now you know how to create timestamps from time/date values and strings. You can also go the other
                         way, and convert a timestamp to its corresponding date and time components.












                                                                                                         475





          c16.indd   475                                                                              9/21/09   9:15:28 AM
          c16.indd   475
                                                                                                      9/21/09   9:15:28 AM
   508   509   510   511   512   513   514   515   516   517   518