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

Unit 8: Working with Strings, Date and Time



                   setlocale(LC_ALL, “en_US”);                                                    Notes

                   putenv(“TZ=EST”);

                   echo strftime(“%c\n”);
                   echo “\nMET in nl_NL:\n”;

                   setlocale(LC_ALL, “nl_NL”);

                   putenv(“TZ=MET”);
                   echo strftime(“%c\n”);

                   echo “\nMET in no_NO:\n”;
                   setlocale(LC_ALL, “no_NO”);

                   putenv(“TZ=MET”);

                   echo strftime(“%c\n”);
                   echo “\nIST in iw_IL:\n”;

                   setlocale(LC_ALL, “iw_IL”);
                   putenv(“TZ=IST”);

                   echo strftime(“%c\n”);

            ?>
            Output. is
            MON Mar       1      20:19:20       2004

            EST in en_us:
            MON Mar       1      14:19:20       2004

            MET in nl_Nil:
            Na 01 nrt 2004       20:19:20       MET

            IST in iw_IL:
            IST                  21:13:20       2004

            March 1 in different locales.
                          You need to have the locales and time-zone settings installed on your system
                          before this will work. It is a system-dependent setting and not everything is
                          always available on your system. If you’re a Mac OS X user, have a look at
                          http://www.macmax.org/locales/index_en.html to install locales.

            8.4 Parsing Date Formats


            The opposite of formatting text is parsing a textual description of a date into a timestamp. The
            strtotime() function handles a many different formats.  Table contains a list of the most useful
            formats.



                                             LOVELY PROFESSIONAL UNIVERSITY                                   137
   137   138   139   140   141   142   143   144   145   146   147