Manish Pansiniya's Blog

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

Posts Tagged ‘DateTime Format

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


Written by Manish

June 3, 2010 at 4:31 pm