Zoom application, display DateTime

For the developed application, we use the format "G"everywhere in our application.

We want to change this format a bit:

We need to display the first digit after the second.

Example:

07/29/2014 08: 54: 36.1

We would like to be able to change this into CurrentCulture.

This is the only thing we want to change in the current culture, therefore, if earlier, we had the following format:

2014/07/29 08:54:36 AM

Then we want to have

2014/07/29 08: 54: 36.1 AM

If before I had

07/29/2014 08:54:36

Then we want to have

07/29/2014 08: 54: 36.1

It would be nice if DateTime, which we get does not have a digit that will be displayed here (= 0 tenth of a second), so that it does not appear.

+1
3

CurrentCulture LongTimePattern:

CultureInfo culture = Thread.CurrentThread.CurrentCulture.Clone();

change the culture.DateTimeFormat.LongTimePattern = "your pattern";

Thread.CurrentThread.CurrentCulture = culture;
+2

, , , , "".

string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.f tt", CultureInfo.GetCultureInfo("en-US"));
0

I would create an extension method for DateTime, something like ToPrettyPrintStringg () or what you want to call, which returns the date in the format you want, so you can make it display any date the way you want it everywhere.

0
source

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


All Articles