What would create these strange characters in the DateTime to String conversion?

I have some code that writes DateTime

to some output files:

 DateTime dateTime = DateTime::Now;
 String^ value = String::Format("{0} {1}", dateTime.ToShortDateString(), dateTime.ToLongTimeString());

      

... which seems to give some odd outputs on the client machine:

2014-12-16 오전 12:00:00

      

What might be causing these extra characters to appear?

+3


source to share


3 answers


This is reasonable enough if the user is in a different region - you should ask your client what their system language is. Use an invariant culture if you want a machine readable format. For example:



String^ value = dateTime.ToString("yyyy-MM-dd HH:mm:ss",
                                  CultureInfo::InvariantCulture);

      

+4


source


These characters stand for "forenoon" in Korean on Wikipedia (see English link), so I'm assuming it's in the client's regional settings that are presented (presumably) ToLongTimeString()

.



+3


source


By using the CultureInfo class , you can always maintain constant date format. Even after accessing a page or file elsewhere. By defining as below

For Ex:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");

      

+1


source







All Articles