HOW TO show UTC Date/Time recorded on the server in the user's regional time zone format.

While I was reading Rick Strahl's commentary of Javascript frameworks & libraries, I remembered how beneficial Matt Kruse's Date library has been to me. The library that comes as a external Javascript file is just 12KB. It has functions to take care of date formatting, parsing, comparing & adding/subtracting dates. I utilized it recently to show UTC Date/Time recorded on the server in the user's regional time zone format using Javascript.

In a web application that reaches to a global audience, having timestamps that reflect the server date-time rather than the user's regional date/time & that too in her regular format can make it impersonal & hinder interactivity. If the date/time values are recorded on the server in UTC (Coordinated Universal Time) format, they can be converted into the browser's local format making it more friendlier.

I wrote a Javascript function to convert a UTC Date/Time into the visitor's local DateTime format using Date.parseString (to convert a DateTime string to a Date object) & Date.add (to add or subtract specific elements of a Date) custom functions from Matt Kruse's Date library. You can view the explanation, source code & output at my code gallery and provide your feedback.

Comments