String Date Conversion Example

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 787
using System.Globalization;

string date = "2014-02-02";

1st example using DateTime.Parse method
DateTime dt = DateTime.Parse(date);
Messagebox.Show(dt);


2nd example using Convert.ToDateTime
DateTime dt = Convert.ToDateTime(date);
Messagebox.Show(dt);


3rd example using DateTime.ParseExact method
string date = "Sun 19 Jan 11:45 AM 2014";
string format = "ddd MMM h:mm tt yyyy";

DateTime dt = DateTime.ParseExact(date,format,CultureInfo.InvariantCulture);
Messagebox.Show(dt);

Comments or Responses

Login to post response