0
Reply

Problem to convert string to DateTime

alpha tran

alpha tran

May 19 2009 12:27 PM
6.1k
When I try to convert a string to DateTime, I got this problem:

private void button1_Click(object sender, EventArgs e)
        {
string st = "05/19/2009";
DateTime dt = Convert.ToDateTime(st, CultureInfo.InvariantCulture ); //result is: {5/19/2009 12:00:00 MO}
string st2 = Convert.ToString(dt, CultureInfo.InvariantCulture ); //reult is: "05/19/2009 00:00:00"

}
MO: is the custom AMDesignator I set in Control Panel, I need it to be "AM" as the AMdesignator of InvariantCulture.DateTimeFormat

So we can say that CultureInfo.InvariantCulture did not effect on the conversion from string to DateTime

.... but in reverse conversion (the second conversion above) it worked ok

by reading many many pages over the internet with many way but no arcticle could help me.

How can I solve this by C# code?