Internet Strategy Guide

tekx – date and time with derick rethans

by on May.19, 2010, under php, phptek, tekx

This is an SVG version of the Time Zone map fr...
Image via Wikipedia

We’re starting with a map of the world showing the 24 major timezones. Timezone changes (daylight savings times) make things tricky. The abbreviations for timezones aren’t enough to determine the user’s timezone. EST can mean different things.

The 64-bit signed integer used internally provides more than enough time for us to use (+/- 90 billion years if I heard correctly). strtotime() and functions with timestamps have been replaced with classes (such as new DateTime()).

The bundled timezone database has 564 zones so far that isn’t dependent on timezone abbreviations. They have the format Continent/Location or Continent/Location/Sublocation like Europe/Amsterdam. Updated database is released 20 times a year. Some changes are very sudden. Basically, you’re timezone database is probably outdated.

You can set the default timezone with a function or the DateTime object. PHP guesses it in the following order:

  • date_default_timezone_set()
  • TZ environment variable
  • php.ini’s date.timezone setting
  • system’s rendering of timezone abbreviation.

PHP 5.3 will not guess and will complain.

You can parse strings with the date_parse() function.

The DateTime object seems very powerful. It allows you to modify times and will account for time zone changes for some of its other uses.

I’m thinking I’ll have to wait for slides, lots of code examples that I’m having a hard time figuring out how to explain in a post. In regards to relative time, remember that time always moves forward. If the date is Wednesday, asking for Tuesday will get the next Tuesday. Yeah, the code examples and output are probably better but will have to wait until I can link to them.

Reblog this post [with Zemanta]
:, , , , ,

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!