Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,


How to convert this " Thu Sep 23 19:34:06 IST 2010" date Time Format into mm/dd/yyyy(US) Format. Is it a Valid Date Time Format. If it is How to convert this into US date Time Format.


Please Help Me through C# Code.
Posted
Comments
Sushil Mate 26-Mar-12 7:35am    
how you getting this kind of date format in C#?

Generally it should be like this "3/26/2012 4:58:19 PM".

That should do the trick:
C#
string time = "Thu Sep 23 19:34:06 IST 2010";
string pattern = "ddd MMM d HH:mm:ss IST yyyy";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime timeVal;
bool bSuccess = DateTime.TryParseExact(time, pattern, culture, DateTimeStyles.AllowWhiteSpaces, out timeVal);
MessageBox.Show(timeVal.ToString("MM/dd/yyyy"));
 
Share this answer
 
Comments
ProEnggSoft 26-Mar-12 9:39am    
Nice answer. 5!
First create a datetime object from this available string you have and then the to string has an overloaded version which takes the format to convert to, you can use

C#
DateTime.Now.ToString("MM/dd/yyyy");
 
Share this answer
 
v2
Comments
sacraj 26-Mar-12 6:19am    
I am unable to convert this

string sDate = "Wed Nov 10 14:13:10 IST 2010";
DateTime dDate = Convert.ToDateTime(sDate);

When I run this above code I get an Exception saying that"
String was not recognized as a valid DateTime."

How can I convert this string into date Time Format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900