Converting a String to DateTime

后端 未结 17 2575
南方客
南方客 2020-11-21 06:12

How do you convert a string such as 2009-05-08 14:40:52,531 into a DateTime?

17条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 06:52

    string input;
    DateTime db;
    Console.WriteLine("Enter Date in this Format(YYYY-MM-DD): ");
    input = Console.ReadLine();
    db = Convert.ToDateTime(input);
    
    //////// this methods convert string value to datetime
    ///////// in order to print date
    
    Console.WriteLine("{0}-{1}-{2}",db.Year,db.Month,db.Day);
    

提交回复
热议问题