How to display a date in a specific language

I do some of my developing on German servers which was always a drag when it came to formatting dates. With .NET you can set the culture info and it is taken care of automatically for you. Nice.

// using System.Globalization // stick this at the top of your class

CultureInfo ci = new CultureInfo("en-US");
DateTime dt = DateTime.Now;
Response.Write(dt.ToString("f",ci));

Response.Write("<br><br>");

DateTime dt2 = DateTime.MinValue;
Response.Write(dt2.ToString("f",ci));

You might also like...

Comments

Edward Tanguay Edward Tanguay updates his personal web site tanguay.info weekly with code, links, quotes and thoughts on web development. Sign up for the free newsletter.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski