Skip to content

Changing the DateTime textbox to UK Date Format

January 22, 2013

Last week on Friday, as well as making the JQuery DatePicker changes to the UK Date Format, I had made all the significant changes to the text box fields displaying the Date Time including date range validation which I can write on a later post. Here are the details of the changes:-

System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
provider = new System.Globalization.CultureInfo(“en-GB”);

txtStartTime.Text = Convert.ToDateTime(selectedSubscription.ValidFrom, provider).ToString(“dd/MM/yyyy hh:mm”, provider);

 

Notice here that I have added the date time format on the first parameter in ToString() with “dd/MM/yyyy hh:mm with provider set to en-GB for the UK date format.

You can customise this to anything you want for the date time field parameter.

If you don’t include dd/MM/yyyy hh:mm, it will set to the standard US date time format, which if you leave this out for any text field. So make sure you do this for all.

 

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: