C# to Convert String to DateTime

前端 未结 6 1924
北海茫月
北海茫月 2020-12-21 11:59

How to convert the below string to DateTime in C#?

Mon Apr 22 07:56:21 +0000 2013

When i tried the code with

         


        
6条回答
  •  萌比男神i
    2020-12-21 12:40

    You can use this:

    using System;
    using System.Globalization;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                CultureInfo cult = CultureInfo.InvariantCulture;
    
                string txt = "Mon Apr 22 07:56:21 +0000 2013";
                string format = "ffffd MMM dd hh:mm:ss zzz yyyy";
                DateTime dt = DateTime.ParseExact(txt, format, cult);
    
            }
        }
    }
    

    If you run program from country with +06:00, you get time 13:56:21 with same date

提交回复
热议问题