AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Tuesday, 3 November 2015

Key points to remember during DateTime conversion in c#.

DateTime conversion

In this blog article I am given some important tips for conversion of DateTime in c#. If we want to convert datetime in string format like (dd/MM/yyyy) then most of us write code as like.

Some times we found that output is like 7-8-2015. However our supplied conversion format is dd/MM/yyyy.
The / character in DateTime format strings stands for "whatever the date separator of the format provider is". Since We do not supply a format provider Thread.CurrentCulture is used, and in your case the current culture uses . as the date separator.
Another way, we can specify a format provider where date separator is /
DateTime.Now.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);


Post a Comment

  • Popular Posts
  • Comments