Wednesday, December 12, 2007

Interesting/weird feature of DateTime.ToString()

I was playing around with localization when I encountered the following behaviuor: I set time & number format to "French (Canada)", and wrote:

DateTime.Now.ToString("dd/MM/yyyy")

I got:
12-12-2007

Instead of "/" I got "-".

I was looking around and couldn't find any documentation saying '/' is a special character in DateTime format string. Finally I used the following string which worked just fine:

DateTime.Now.ToString(@"dd\/MM\/yyyy")

No comments: