tags:

views:

395

answers:

2

Hi,

i am trying to understand how DateTime.ToString(Date pattern) work in .net framework, C#.

I changed my computer to have a short Date format like this yyyy.MM.dd. Following is what I notice

DateTime myDate = DateTime.Now;

myDate.ToString("yyyy/MM/dd") always return in the format of yyyy.MM.dd not yyyy/MM/dd
and
myDate.ToString("yyyy-MM-dd") does return string in the format of yyyy-MM-dd

to have it return what i was looking for, this is what i need to do myDate.ToString("yyyy'/'MM'/'dd") ===> yyyy/MM/dd

Can anyone explain to me why it is doing that? and is there any other way i can achieve the same result?

thanks....

+3  A: 

/ is considered a format specifier and is replaced just like yyyy is.

Read the information on the format specifiers:

/ = The default date separator defined in DateSeparator.

Andreas Bonini
thanks, i guess I have to manually escape the "/" character by putting single quote around them then.thanks
Eatdoku
A: 

You're getting the behavior you're seeing because "/" is a format specifier.

If you look at the custom date format settings help, you'll see that "/" translates as the date separator for your culture.

Reed Copsey