Date Time in English United Kingdom

Date Time in English United Kingdom

In this example we will see how to accepts a input date time string in English UK format. Example uses CurrentCulture information of running thread, C#.net and Vb.net

C# Get input date in English UK format

The DateTime format used in UK is DD/MM/YYYY. Here we will look at culture information and change it to English UK

  
using System;
using System.Globalization;
using System.Threading;
namespace DateAndTime.Example
{
class Program
{
static void Main(string[] args)
{
CultureInfo ci = new CultureInfo("en-GB");       
Thread.CurrentThread.CurrentCulture = ci;           
string inputDate = "30-04-2011";      
DateTime dt = DateTime.Parse(inputDate);            
Console.WriteLine("Current time of the system in {0}",dt.ToString());
Console.ReadLine();
}
}
}
Output
Current time of the system in 30/04/2011 00:00:00

Date Time in English united kingdom

Vb.Net get input date in English UK format

Below example uses Vb.net code to accept date time in UK format. It uses using System.Globalization and using System.Threading as a namespace to change current culture of running thread.

Imports System.Globalization
Imports System.Threading
Namespace DateAndTime.Example
Class Program
Private Shared Sub Main(args As String())
Dim ci As New CultureInfo("en-GB")
Thread.CurrentThread.CurrentCulture = ci
Dim inputDate As String = "30-04-2011"
Dim dt As DateTime = DateTime.Parse(inputDate)
Console.WriteLine("Current time of the system in {0}", dt.ToString())
Console.ReadLine()
End Sub
End Class
End Namespace

String was not recognized as a valid DateTime.

If the current threading culture is en-US which accepts date and time in MM/DD/YYYY format and input date time string is in DD/MM/YYYY. The application will throw an error "String was not recognized as a valid DateTime." To overcome this error, you need to change the current thread of the system or UI.

More information about date and time [c#], [vb.net]

Get Current time and date of the system.
Get Today's date

Tags:

C# DateTime DifferenceDate Time in English United KingdomDateTime.Today Vs DateTime.NowC# DateTimeC# Parse method of DateTimeAsp.net Cache ObjectDateTime in C# current Date and TimeDateTime ParseExact Time 10:10:13 AM hh mm ss tt nullC# DateTime ToString()DateTime format Time StringDateTimeTryParse with IFormatProvider culture information using c#

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.