Join Kevin Skoglund for an in-depth discussion in this video Sort cities by offset, part of Easy PHP Projects: Time Zone Conversion.
- [Voiceover] In the previous movie, we were able…to use PHP to list 25 major cities…around the world with their current times.…But the list was sorted in the…default order of our cities array.…In my case, that was sorted by city size.…Instead, I'd like that list of cities…to be sorted by the current time.…Or more accurately, by the offset from the UTC timezone.…Making this change requires 3 steps.…First, we need to loop through the cities array…that we already have, in order to build an array…which includes those offset values.…
Once we have those offset values available…for all the cities, we can sort our array by the offsets.…And then, we loop through the sorted array…in order to do the output.…So it's three steps: Get the offset values,…sort by the offset values, and then do the output.…The easiest way to do this is to put a new loop here…before we have our foreach, and we're gonna loop…through the cities, find their offsets,…and build up a new array.…So I'm going to create a temporary array here.…
Output array, and it's just going to be equal to…
- Understanding the history and purpose of time zones
- Setting a default time zone in PHP
- Using the PHP DateTime and DateTimeZone classes
- Working with daylight saving time transitions
- Allowing users to select their time zone
- Displaying times in the user's preferred time zone
- Calculating the current times of major cities
- Creating a complete time zone calculator
Skill Level Beginner
1. About Time Zones
2. Default Time Zone
3. Working with Time Zones in PHP
4. User Time Zone Selection
5. Respect the User's Time Zone
6. Current World Times
7. Time Zone Calculator
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.