Modify application wide, the display of DateTime

后端 未结 3 657
北荒
北荒 2021-01-25 03:12

For an application we develop, we use the \"G\" format everywhere in our application.

We want to change a little bit this format:

We need to display

相关标签:
3条回答
  • 2021-01-25 03:38

    I tested this and looks like is returning what you are looking for except for the "nice to have".

    string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.f tt", CultureInfo.GetCultureInfo("en-US"));
    
    0 讨论(0)
  • 2021-01-25 03:55

    You can set the CurrentCulture for the current thread and specify a deviating LongTimePattern:

    CultureInfo culture = Thread.CurrentThread.CurrentCulture.Clone();
    
    change the culture.DateTimeFormat.LongTimePattern = "your pattern";
    
    Thread.CurrentThread.CurrentCulture = culture;
    
    0 讨论(0)
  • 2021-01-25 03:55

    I'd create an extension method for DateTime, something like a ToPrettyPrintStringg() or whatever you wanna call it that returns the date in the format you wish, this way you can get it to display any date the way you want everywhere.

    0 讨论(0)
提交回复
热议问题