Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I am new to C# world and this forum as well,
My requirement is that a string I am getting from XML and string is like this

"
2017-01-17T00:00:00Z
"

I want to convert this into Date time so that i can further proceed .

Suggest me
Thanks.

What I have tried:

..............................................................................
Posted
Updated 27-Feb-17 20:15pm
v2

Hello,

You can simply code like this:

var date = Convert.ToDateTime("2017-01-17T00:00:00Z");


Please Mark as answer if helpful for you.
 
Share this answer
 
v2
Try DateTime.TryParse Method (String, DateTime) (System)[^]. An example:
using System;
					
public class Program
{
	public static void Main()
	{
        string input = "2017-01-17T00:00:00Z";
        DateTime dateTime;
        if (DateTime.TryParse(input, out dateTime))
        {
            Console.WriteLine(dateTime);
        }
        else
        {
            Console.WriteLine("Invalid");
        }
	}
}
 
Share this answer
 
Comments
Member 13027678 28-Feb-17 2:17am    
Just I wanted to know in that string what is 'T' and 'Z'
Thanks
Peter Leow 28-Feb-17 2:39am    
T as delimiter https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations
Z for UTC time https://en.wikipedia.org/wiki/ISO_8601#UTC
Hi peter ,Thanks for prompt reply
your code worked for me .

Thanks
 
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