开发者

date format in asp.net versus in console application

I'm deploying a .NET applications to another machine.

in console application, the value of

DateTime.Today开发者_JAVA百科.ToLongDateString();

is

10 December 2009

while in web application the value is

23 ذو الحجة 1430 < equivalent in higri calendar

How does the web application get the culture from, and why is it different than the console application?


In the web.config or machine.config you can specify the default culture for the ASP.Net application through the globalization element.

<configuration>
  <system.web>
    <globalization 
      culture="en-US"/>
  </system.web>
</configuration>


It gets it from the machine. See here how you can change it.


It's likely to be the culture of the machine itself - you say you're deploying to a different machine.

Which culture do you want it to be in?

EDIT: Your options are:

  • Set the culture for the machine itself, affecting the whole of Windows
  • Possibly set the culture for .NET in general - I'm not sure whether this is available or not in machine.config. It's not something I've ever done.
  • Set the culture for each page
  • Specify the culture explicitly whenever you parse or format strings

The last one is the least invasive, to be honest. Most methods like String.Parse etc have an overload with an IFormatProvider parameter. You can specify this as the relevant CultureInfo.


I got the answer! it was one of the registry records of the users of probably ASPNET or IIS. by using regedit, i found in one of the users international = arabic

Thanks to: Change Default Locale in IIS 6.0


Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
DateTime.Today.ToLongDateString();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜