How to update a short time string (C # DateTime.Now)?

I am making Notepad using Windows Form and have a problem with the Date / Time function:

System time and date format (short): hh: mm tt M / d / yyyy. When I press F5 (Date / Time function) in Notepad, it adds a time line with the format as above. Then I change the format of the system time and date to HH: mm dd-MMM-YY and again press F5 in Notepad, adding another time line with the changed format.

But with my Notepad project (I use DateTime.Now.ToShortTimeString()it DateTime.Now.ToShortDateString()to execute this function), I need to run the program again if I want the format to take effect in my program, otherwise it will use the first format no matter how many times I click F5.

So, I want to ask if there is a way to fix this.

I am using VS 2013.

+4
source share
2 answers

Very good question. The date is formatted according to the current culture information of the user, but the information is cached by .NET. What you need to do is force .NET to clear the cache by calling the method CultureInfo.ClearCachedDatain advance.

Additional information here: https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.clearcacheddata(v=vs.80).aspx

, , , - (, ). , , , , . , SystemEvents.UserPreferenceChanged. : ,

+7

SystemEvents , UserPreferenceChang *.

+1

All Articles