csharp Creating new DateTime

DateTime newDate = new DateTime(2010, 5, 14);
Console.WriteLine(newDate);//2010-05-14 00:00:00
Console.WriteLine(newDate.ToString("yyyy-MM-dd"));//2010-05-14

DateTime newDate2 = new DateTime(
	Convert.ToInt16(DateTime.Now.ToString("yyyy")),
	Convert.ToInt16(DateTime.Now.ToString("MM")),
	Convert.ToInt16(DateTime.Now.ToString("dd"))
);
Console.WriteLine(newDate2);//2010-10-22 00:00:00
Console.WriteLine(newDate2.ToString("yyyy-MM-dd"));//2010-10-22
Example of creating a new DateTime variable.

Updated: Friday 22nd October 2010, 10:56pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.