Google Search: c# convert date from uk to usa

One of the searches that came from Google to my site asked the following "c# convert date from uk to usa".

Now I don't really know exactly what the user was asking for, but I presume it is something fairly simple. The way that I would convert a UK date into a US date is as follows.

Read in the UK date, short format/long format whatever into a DateTime field. The output the date time using a US locale.

The following code works in vs2005.

CultureInfo cultEnGb = new CultureInfo("en-GB");CultureInfo cultEnUs = new CultureInfo("en-US");DateTime dtGb = Convert.ToDateTime(textBox1.Text, cultEnGb.DateTimeFormat);textBox2.Text = dtGb.ToString(cultEnUs.DateTimeFormat.ShortDatePattern);

It reads in the date and tries to load the text as a UK Date from the first textbox and then it uses the US locale to output the string into the second textbox.

I lead the Chrome Developer Relations team at Google.

We want people to have the best experience possible on the web without having to install a native app or produce content in a walled garden.

Our team tries to make it easier for developers to build on the web by supporting every Chrome release, creating great content to support developers on, contributing to MDN, helping to improve browser compatibility, and some of the best developer tools like Lighthouse, Workbox, Squoosh to name just a few.

I love to learn about what you are building, and how I can help with Chrome or Web development in general, so if you want to chat with me directly, please feel free to book a consultation.

I'm trialing a newsletter, you can subscribe below (thank you!)