Date format in ASP.Net

In this article I will show how the use of culture in the web.config file does not work as expected with the format of the date and other information.

Before starting, it is important to explain about the CultureInfo class. The CultureInfo Class Provides information about a specific culture. The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.

How to use

You should be parsing the string to a DateTime and then format it to the second format using ToString() method. Example in C#:


DateTime dt2 = DateTime.ParseExact(date31strin, “MM-dd-yyyy HH:mm:ss”, CultureInfo.InvariantCulture);

string secondFormat = dt2.ToString(“Second format string”);

And that’s it! This will ensure you do not have problems when you work with date formats in your ASP applications.

This concludes Date format in ASP.Net

Looking for quality Windows Hosting? Look no further than Arvixe Web Hosting!

Happy Hosting

Tags: , , , , , , , , , | Posted under ASP .NET 2, ASP .NET 4.0, MSSQL | RSS 2.0

Author Spotlight

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

Your email address will not be published. Required fields are marked *