CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Format DateTime based on Country or Culture in C#, ASP.Net
Submitted By Satheesh Babu B
On 4/10/2011 12:09:04 AM
Tags: CodeDigest  

Format DateTime based on Country or Culture in C#, ASP.Net/How to get Datetime formatted to a specific country in ASP.Net ?

 

We can format the DateTime object specific to a country/culture by passing the CultureInfo object with the format string in ToString() method.

The below code snippet will print the short date using the de-GE(Germany) culture format.

protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Now;
        Response.Write(dt.ToString("d",new CultureInfo("de-DE")));

    }


Include System.Globalization namespace for the above code to work.

 

In the above code, replace the language-culture code to the target culture you require.

 

Click here to get the list of language-country code for using in CultureInfo class.

 

Read the below article to know more about formatting DateTime strings.
Working with DateTime Object and Formatting DateTime Object in ASP.Net

 

Happy Coding!!


 

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..