Click here to Skip to main content
14,027,514 members
Rate this:
 
Please Sign up or sign in to vote.
Hi,

    i am android and Ios developer, i would like to convert string to DateTime

    `string nodeValue = "2013-02-11T14:29:01-05:00";`

    The nodeValue comes from after converting DataSet to XMLDocument

    how can i get the DateTime value as 2/11/2013 2:29:01 PM?

    Help me please...


What I have tried:

i tried by using Convert.ToDateTime(nodeValue) but it is not returning expected result.
Posted
Updated 21-Feb-19 3:00am
Comments
W Balboos 21-Feb-19 8:03am
   
Google it - not much harder than posting here.
And bookmark the anyplace that's a good reference.
Korlakunta 21-Feb-19 8:06am
   
i tried to google it but i did not find expected solution
W Balboos 21-Feb-19 8:09am
   
Expected Solution?
If you know what to expect then do it.
If you don't know how to do it how can you expect anything?

In either case - you call yourself a 'developer'. No - you want to be a developer. You've a ways to go.
Korlakunta 21-Feb-19 8:13am
   
Expected Solution means after conversion string to datetime 2/11/2013 2:29:01 PM

Thank You
W Balboos 21-Feb-19 8:15am
   
A developer needs to use their brains and figure things out. If you think you'll find everything exactly as you want it you are in the wrong business.
Kevin Marois 21-Feb-19 11:08am
   
Your entire response was rude & uncalled for. What's the point of having forums if you can't post questions without someone like you flaming the guy. He said he Googled it and didn't find what he's looking for, so he posted here, where he hoped to find someone who could help him with his problem.

Instead hey gets YOU, who, instead of helping him either narrow his search or provide an answer, you choose to insult him.

You said to him "In either case - you call yourself a 'developer'. No - you want to be a developer. You've a ways to go." So because he's not as bright as you he's not a developer?

You're one of the smarter folks here on CP and you've helped me more than a few times, but if you don't have an answer, then don't reply. And certainly don't flame the poor guy who's just trying to do his job.
Korlakunta 22-Feb-19 0:38am
   
Brother,Response should be like polite way not something else
Korlakunta 21-Feb-19 8:20am
   
Thank you for your suggestions
David Crow 24-Feb-19 22:30pm
   
Have you tried this?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

DateTime myDate = DateTime.ParseExact("2013-02-11T14:29:01", "yyyy'-'MM'-'dd'T'HH':'mm':'ss", System.Globalization.CultureInfo.InvariantCulture);


I have used 2013-02-11T14:29:01 instead of 2013-02-11T14:29:01-05:00 and its showing date time as per the requirement.

Thank You
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

string nodeValue = "2013-02-11T14:29:01-05:00";
	DateTime result = DateTime.Parse(nodeValue);
	Console.WriteLine(result);


2/11/2013 1:29:01 PM

Be aware that if the string is not a valid date an exception will be thrown
in that case use TryParse
ring nodeValue = "2013-13-11T14:29:01-05:00";
	DateTime result;
	 DateTime.TryParse(nodeValue, out result);
	Console.WriteLine(result);


1/0001 12:00:00 AM
   
v3
Comments
Korlakunta 21-Feb-19 8:19am
   
i am able to see result value as 2/12/2013 12:59:01 AM
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Finally got solution

             string nodeValue = "2013-02-11T14:29:01-05:00";
             DateTimeOffset dtOffset;

             if(DateTimeOffset.TryParse(nodeValue,null,DateTimeStyles.None,out dtOffset))
             {
                 DateTime myDate = dtOffset.DateTime;

                    //output myDate
                   //2/11/2013 2:29:01 PM
             }
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190419.4 | Last Updated 21 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100