Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am fetching some data from some API, the date am getting is as below: {dd/MM/yyyy hh:mm:ss} "6/15/2014 6:45:00"

Is there anyway I can directly convert it to date time ? Please guide.. Thanks in advance.


What I have tried:

I tried .ToString(""), Convert.ToDateTime() and Parse/ExactPare but nothing work. 
Posted
Updated 10-Aug-18 2:06am

1 solution

Try:
string date = "6/15/2014 6:45:00";
DateTime dt;
if (DateTime.TryParseExact(date, "M/d/yyyy h:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
    {
    Console.WriteLine(dt);
    }
 
Share this answer
 
Comments
rooohit 10-Aug-18 8:25am    
thanks a lot...
OriginalGriff 10-Aug-18 8:27am    
You're welcome!

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