开发者

Changing Date Display format based on the Selected Time Zone

开发者 https://www.devze.com 2023-02-25 08:13 出处:网络
I have list of all time zones in world.My goal is to display the date and time based on the time zone selected by the user or client.

I have list of all time zones in world.My goal is to display the date and time based on the time zone selected by the user or client.

 i.e. in the US we list DD/MM/YY.开发者_JAVA百科 In India they use MM/DD/YY.

How do i achieve this?Is there any possibility of changing the date format based on the time zone selected?

Pls provide any suggestions or sample coding to achieve this....

I wanted to know whether date format can be changed based on the Time zone selected?


because there is no way on clientside to achive this, my suggestion is select the time zone on clientside, make an ajax request to the server, generate the time zone on server side (if possible) and display it in browser.


Use the Date.toLocaleDateString() method. It will convert the dates into the format determined by end-user's system settings:

var d = new Date("20/10/2000");
d.toLocaleDateString();

The important thing to note is that the user must have set correct regional settings on his/her computer. Many people do not bother to change them and instead choose the default (en-us) when they install the operating system.


This depends on the active culture. First option is to change the culture to the one you want and then just print out the date.

public static void Set(string culture)
{
  Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
}


There are a couple times it is helpful to know 'which' format the user computer assigns for date and month formatting.

You can determine this once, and use it to arrange your inputs and sidplay value everywhere-

Date.ddmm= (function(){
    return Date.parse('2/6/2009')> Date.parse('6/2/2009');
})(),

//returns true if format is dd-mm-yyyy, false otherwise

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号