How to get current short DateTime format in C #?

How do I get the local system's DateTime format in string format using C #?

For example: dd/MM/yyyy or MM/dd/YYYY

+6
source share
2 answers

Try the following:

 using System.Globalization; ... ... ... var myDTFI = CultureInfo.CurrentCulture.DateTimeFormat; var result = myDTFI.FullDateTimePattern; 
+8
source

Overkill, but should do it:

 CultureInfo info = null; var thread = new Thread(() => { info = Thread.CurrentThread.CurrentCulture; return; }); thread.Start(); thread.Join(); // info.DateTimeFormat.ShortDatePattern 

Based on the fact that new threads should inherit the standard culture of the system (I consider it a missing feature: it is almost impossible to control the culture of new threads, read here is there a way to configure the culture for the whole application? All current threads and new threads? ). I do not use Thread.CurrentThread.CurrentCulture directly, because someone could talk to him Thread.CurrentThread.CurrentCulture

+2
source

Source: https://habr.com/ru/post/896774/


All Articles