I've got a database that holds a period as UTC. This time around could be proven inside a web page, so I’ve been requested to exhibit it as being local amount of time in the page as possible seen from the country. A friend pointed out something about obtaining the country configurations in the current thread (around the server) however i couldn’t find any particulars about this. Is exactly what I wish to do possible?
First, around the server side, you'd possess the UTC date/time formatted in RFC 3339 format (the conventional for internet time utilized by, among other methods, icalendar). The fundamental syntax of RFC 3339 is:
So that where I'm, time could be:
However when time isn't local, but UTC, you give a
Z towards the finish to denote this. So during my situation, since I am at -0500 hrs from GMT, the same time frame above could be:
var time_string_utc = some_server_variable; // timestamp from server var time_string_utc_epoch = Date.parse(some_server_variable); var time_utc = new Date(); time_utc.setTime(time_string_utc_epoch);
The very first variable assumes you've passed the timestamp string to that particular variable in the server.
The 2nd variable uses the
Date.parse() approach to convert the string for an epoch timestamp.
The 3rd variable produces the unset Date object.
The final line line uses
setTime method, which sets to start dating ? object from an epoch timestamp.
Now that you've got the item, you are able to output it towards the user as you can see fit. Like a simple experiment, you should use:
which, if you're during my timezone while using UTC timestamp I began served by:
Tue May 04 2010 05:52:33 GMT-0500 (CST)
You don't need to guess anyone's country as well as adjust your timestamp, as long as you trust anyone's local browser/computer time zone.
Again, rapid version:
var time_string_utc = some_server_variable; // UTC time from server var time_string_utc_epoch = Date.parse(some_server_variable); var time_utc = new Date(); time_utc.setTime(time_string_utc_epoch); document.write(time_utc);
Of-course can be done. You need to simply discover that
country settings to identify the nation your user originates from, after which customize the displayed date to suit that country's time.There are also a different way to identify the consumer country.(maybe from his ip).
I am certain that the easiest method to manage this really is give your friend know that you'll require more particulars concerning the country configurations implementation in your project and just how do you need it.
Considering it I do not think you'll be able to display the neighborhood time after you have the client’s culture. I'd easily be interested to visit your co-workers suggestion.
Obtaining the US culture, for instance, will not help because the US has numerous timezones.
You are able to override the InitializeCulture() method with code that sets the present (selected or browser confirming) cultures:
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);