<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


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.

Labels: ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment