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!!
|