tags:

views:

37

answers:

2

Hi There I wish to convert my string in format dd/mm/yyyy hh:mm:ss to a DateTime of the same format.

Dim ukCulture As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-GB")
Dim myDateTime As DateTime
myDateTime = DateTime.ParseExact("18/05/2010 23:42:10, "dd/MM/yyyy HH:mm:ss", ukCulture)

When I step through this code the variable myDateTime is 05/18/2010 23:42:10 it appears that the dd/mm is the wrong way around and I cant work out how to correct this. Can ayone offer any guidance on how to correct this please?

A: 

may be you should review your web.config and add section

globalization culture="en-GB"

shmandor
Have tried en-uk and that doesnt work
WizardsSleeve
<globalization culture="en-GB"/>
shmandor
+2  A: 

The visualiser you are using to inspect the value of the datetime variable is rendering it in US format. The value stored is the actual date and time, and is correct. It's purely a visualisation problem - the code is working. You can format the datetime value to anything you want for your purposes if you need it as a string.

David M
Oh right, how would one go about correcting that in visual studio 2010? Many Thanks
WizardsSleeve
What are the regional settings on your machine set to? It should be just picking those up.
David M
My region settings are correctly set to the UK.
WizardsSleeve
I've just checked on this. The date time is represented in US format when inspected while debugging, and this cannot be configured. Sorry.
David M
Thats ok :) Morning wasted trying to work this out. Thanks for all the help!
WizardsSleeve
Now when I display my date time variable it loses the seconds fields of the end of the time, how can I get this to display? Thanks
WizardsSleeve
When you say "display", do you mean in the debugger, or in your application? If the latter, post some code and we'll tell you what needs to change.
David M