date format in asp.net versus in console application

后端 未结 5 1772
栀梦
栀梦 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.

提交回复
热议问题