0

I try to add to my ASP.NET Website new language support (English).

But all my dateTime format changed from

enter image description here

to

enter image description here

when I change language to "en-EN".

To solve it I write following code:

CultureInfo cultureInfo = new CultureInfo("en-EN");
cultureInfo.DateTimeFormat.FullDateTimePattern = "dddd, d MMMM yyyy 'y.'";
cultureInfo.DateTimeFormat.FullDateTimePattern = "dd MMMM yyyy  'y.'";
cultureInfo.DateTimeFormat.FullDateTimePattern = "d MMMM yyyy 'y.'";
cultureInfo.DateTimeFormat.DateSeparator = ".";
cultureInfo.DateTimeFormat.ShortDatePattern = "d.M.yy";
cultureInfo.DateTimeFormat.ShortDatePattern = "d.MM.yy";
cultureInfo.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";

System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;

But my dateTime format still like d\M\yyyy.

What is wrong? Please help!

Urma
  • 188
  • 3
  • 13
  • Just try with .ToString(''d\M\yyyy") – Md. Abdul Alim Aug 28 '18 at 02:59
  • What does "it still in same format" mean? Your code only shows the definition of some culture settings; it doesn't show us how to reproduce whatever problem you're having. If I run your code and then display a date with something like `Console.WriteLine(DateTime.Today);`, the date format reflects the settings you've defined. – Joe Farrell Aug 28 '18 at 03:00
  • @JoeFarrell I mean my date time still in `d\M\yyyy` format – Urma Aug 28 '18 at 03:19
  • What is "my date time"? You haven't shared any code that prints a `DateTime`, so there is no way to guess why your culture settings aren't working as you expect. In other words, you haven't provided a [complete example](https://stackoverflow.com/help/mcve). – Joe Farrell Aug 28 '18 at 03:25
  • @JoeFarrell wherever DateTime is used. For ex.: `@Html.DevExpress().Label(s => { s.Name = "dateCreated"; s.Style.Add(HtmlTextWriterStyle.FontWeight, "bold"); s.Style.Add(HtmlTextWriterStyle.Color, "#808080"); }).GetHtml()` – Urma Aug 28 '18 at 03:33
  • Please read the link I shared in my comment above as it will help you write a better question. Nobody can tell you what's wrong with your code if you don't share the code that's failing. – Joe Farrell Aug 28 '18 at 03:34
  • I'm stupid. I had to change date time format in server settings. – Urma Aug 28 '18 at 05:16
  • Is that a telerik grid? – Spider Aug 28 '18 at 06:04

3 Answers3

1

Check this complete understanding of time formatting:- https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Examples:-

DateTime.Now.ToString("MM/dd/yyyy") 05/29/2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")    Friday, 29 May 2015 05:50:06
DateTime.Now.ToString("MM/dd/yyyy HH:mm")   05/29/2015 05:50
DateTime.Now.ToString("MM/dd/yyyy hh:mm tt")    05/29/2015 05:50 AM
DateTime.Now.ToString("MM/dd/yyyy H:mm")    05/29/2015 5:50
DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 05/29/2015 5:50 AM
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")    05/29/2015 05:50:06
DateTime.Now.ToString("MMMM dd")    May 29
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") 2015-05-16T05:50:06.7199222-04:00
DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") Fri, 16 May 2015 05:50:06 GMT
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss")  2015-05-16T05:50:06
DateTime.Now.ToString("HH:mm")  05:50
DateTime.Now.ToString("hh:mm tt")   05:50 AM
DateTime.Now.ToString("H:mm")   5:50
DateTime.Now.ToString("h:mm tt")    5:50 AM
DateTime.Now.ToString("HH:mm:ss")   05:50:06
DateTime.Now.ToString("yyyy MMMM")  2015 May
Ankur Tripathi
  • 471
  • 2
  • 16
1

you need to change server or local computer date settings For example: Settings--> Time & Language --> Region --> Format:( Here you need to change country) --> Additional Settings --> Date You can change date format

Good Luck :)

0

You might be experiencing that en-EN is the Original English (as in English English and not American English), which represent date values with forward/back-slashes, while American notation of dates usually use dashes (-). If you use Excel, try typing in a date with dashes and forward slashes for the 2nd of January, and you should see it the different notations flip the the numbers around.

What you're experiencing is probably .NET enforcing the correct Cultural Notation, but you should still be able to format the date like @Md._Abdul_Alim mentioned using the .toString(format).

https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Guy Park
  • 959
  • 12
  • 25