Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Custom Format Specify in DateTime Format String C#

with one comment

Whenever we specify / in the DateTime format, it shows and convert the DateTime Separator that is setup in your regional settings.

so DateTime.Now.Date.ToString(@"d/MM/yyyy") will display “3-06-2010” on my pc as my regional setting has “–” as datetime separator.

If you require / in the date (or if you need any char as it is without converting it to Format specified in DateTime) then you need to add escape char before the char you require.

And that is the reason, DateTime.Now.Date.ToString(@"d\/MM\/yyyy") will give you “3/06/2010”

🙂 Happy ProgRaMMing

Advertisements

Written by Manish

June 3, 2010 at 4:31 pm

One Response

Subscribe to comments with RSS.

  1. Thanks

    PR

    January 28, 2012 at 11:05 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: