Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would produce these strange characters in a DateTime to String conversion?

Tags:

.net

datetime

I have some code which records a DateTime in some output files:

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

...which is apparently giving some odd outputs on a customers machine:

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

What might be causing those additional characters to appear there?

like image 703
Jon Cage Avatar asked Jan 23 '26 03:01

Jon Cage


2 Answers

That's fairly reasonable if the user is in a different locale - you should ask your customer what their system locale is. Use the invariant culture if you want a machine-readable format. For example:

String^ value = dateTime.ToString("yyyy-MM-dd HH:mm:ss",
                                  CultureInfo::InvariantCulture);
like image 147
Jon Skeet Avatar answered Jan 25 '26 19:01

Jon Skeet


Those characters mean "forenoon" in Korean according to Wikipedia (see English link), so I guess it's in the client's regional settings, which are represented through (presumably) ToLongTimeString().

like image 44
CodeCaster Avatar answered Jan 25 '26 18:01

CodeCaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!