How to parse date time value from a string in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "2017-01-18 14:46:30";

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

/*
run:
   
18/01/2017 14:46:30

*/

 



answered Jan 18, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "18/1/2017 18:34 PM";

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

/*
run:
   
18/01/2017 18:34:00

*/

 



answered Jan 18, 2017 by avibootz

Related questions

1 answer 165 views
1 answer 145 views
145 views asked Jan 18, 2017 by avibootz
1 answer 165 views
4 answers 222 views
222 views asked Jan 18, 2017 by avibootz
1 answer 155 views
155 views asked Sep 7, 2019 by avibootz
...