Home:ALL Converter>How to set order of DateTime components while also providing CultureInfo

How to set order of DateTime components while also providing CultureInfo

Ask Time:2021-09-22T05:15:34         Author:Bassie

Json Formatter

I have a DateTimeOffset and want to display it like this for en-GB

23/08/2020 09:00

or for en-US:

08/23/2020 09:00

but when I do

dateTimeOffset.DateTime.ToString(new CultureInfo("en-GB"));

It gives me the following (I don't want it to show AM/PM):

23/08/2020 09:00 AM

I know I can do ToString("dd/MM/yyy HH:mm"), but then the format would be wrong for US culture

Author:Bassie,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275634/how-to-set-order-of-datetime-components-while-also-providing-cultureinfo
lidqy :

var date = new DateTime(2020, 8, 23, 9, 0, 0);\n var gbFmt = string.Format(new CultureInfo("en-gb"), "{0:d} {0:HH:mm}", date);\n var usFmt = string.Format(new CultureInfo("en-us"), "{0:d} {0:HH:mm}", date);\n Console.Write("gb: {0}\\nus: {1}\\n", gbFmt, usFmt);\n\n /* gb: 23/08/2020 09:00\n us: 8/23/2020 09:00 */\n \n",
2021-09-21T22:06:48
yy