简体   繁体   中英

migrate from .net3.1 to net6.0 results in 4 letter DateTime abbreviation instead of 3

After migrating from .netcore3.1 to .net6.0 a simple console app now prints out some months with a 4 letter abberviation:

        Console.WriteLine(DateTime.Parse("1-Jul-2022").ToString("MMM"));
        //outputs July, used to be Jul
        Console.WriteLine(DateTime.Parse("1-Sep-2022").ToString("MMM"));
        //outputs Sept, used to be Sep

How to make it revert to the netcore3.1 behaviour? Please note I would like a global solution not one that 'fixes' an invidiual instance of DateTime.ToString( )

My DateTimeFormatInfo.CurrentInfo has Culture en-AU - nothing else has changed on my OS

After following the steps from the link provided by @Hans here are the steps

  1. create a file runtimeconfig.template.json at the root of your project
  2. insert
{
  "configProperties": {
    "System.Globalization.UseNls": true
  }
}
  1. Rebuild project - ensure you see the config changes in the output directory file ConsoleApp.runtimeconfig.json

  2. Check ICUMode is false

public static bool ICUMode()
{
    SortVersion sortVersion = CultureInfo.InvariantCulture.CompareInfo.Version;
    byte[] bytes = sortVersion.SortId.ToByteArray();
    int version = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
    return version != 0 && version == sortVersion.FullVersion;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM