Blogs

EMAIL: info@example.com

Matt Glaman: Formatting time elements to match the current user’s locale

I recently created a Live page to promote my upcoming live coding streams and ways to find my previous ones. I have the times listed. However, times are hard. I first shipped them without specifying the CDT timezone – sorry folks. But still, this is a pain and unfriendly to anyone in a different timezone.

Heck, I even have a hard time translating 24h time format from EDT to CDT, let alone UTC. So I wrote some vanilla JavaScript to transform the times into the current user’s locale – no dependencies! 

Drupal outputs its datetime fields in a time element with the datetime attribute, which contains the datetime string. Here’s an example:


Go to Source
Author: