date format in asp.net versus in console application

后端 未结 5 1760
栀梦
栀梦 2021-01-21 13:44

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

in console application, the value of

DateTime.Today.ToLongDateString();

is

相关标签:
5条回答
  • 2021-01-21 14:18

    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.

    0 讨论(0)
  • 2021-01-21 14:22

    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>
    
    0 讨论(0)
  • 2021-01-21 14:23

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

    0 讨论(0)
  • 2021-01-21 14:29

    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

    0 讨论(0)
  • 2021-01-21 14:39
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    DateTime.Today.ToLongDateString();
    
    0 讨论(0)
提交回复
热议问题