Page 134 - Open Soource Technologies 304.indd
P. 134

Unit 8: Working with Strings, Date and Time



            It’s best not to touch the $is_dst parameter, because PHP usually interprets the date and time   Notes
            correctly.
            If we replace all calls to mktime() by gmmktime(), the parameters passed to the function are
            treated as GMT time, with no time zones taken into account. With mktime(), the time zone that
            the server has configured is taken into account. For instance, if you are on Central European
            Time (CET), passing the same parameters as shown previously to gmmktime output times that
            are one hour “later.” Because the date function does take into account time zones, the generated
            GMT timestamp is treated as a CET time zone, resulting in times that are one hour for non DST
            times and two hours for DST times (CEST is CET+1).

            8.3 Formatting Date and Time


            Making a GMT date with gmmktime() and then showing it in the current time zone with the
            date() function doesn’t make much sense. Thus, we also have two functions for formatting date/
            time: date() to format a local date/time, and gmdate() to format a GMT date/time. Both functions
            accept exactly the same parameters. The first parameter is a format string (more about that in a
            bit), and the second is an optional timestamp. If the timestamp parameter is not included, the
            current time is used in formatting the output. gmdate() and date() always format the date in
            English, not in the current “locale” that is set on your system. Two functions are provided to
            format local time/date according to locale settings: strftime() for local time and gmstrftime() for
            GMT times. Table describes formatting string characters for both functions. Note that the (gm)
            strftime() prefix to the formatting string options with a %.


                                   Table 2: Date Formatting Modifiers

                  Description     Date/    Strftime/   Remarks
                                  gmdate   gmstrime
                  AM/PM           A
                  am/pm           a        %p          Either am or pm for the English
                                                       locale. Other Locates Migh have
                                                       replacements  (for  example,  n1_
                                                       NL has an empty atring here).
                  Century, numeric         %C          Returne the century number  20
                  two digits                           for 2004, and so on.
                  Character, literal%      %%          Use this to place a literal character
                                                       % inside the formatting string.
                  Character, newline       %n          Use  this  to  place  a  newline
                                                       character inside the formatting
                                                       string.
                  Character, tab           %t          Use this to place a tab character
                                                       inside the formatting string.
                  Day connt in    t                    Number  of  days  in  the  month
                  month                                defined by the timestamp.
                  Day of month,            %e          Current day in this month defined
                  leading spaces                       by  the  timestamp.  A  space  is
                                                       prepended when the day number
                                                       is less than 10.
                                                                                Contd...

                                             LOVELY PROFESSIONAL UNIVERSITY                                   129
   129   130   131   132   133   134   135   136   137   138   139