Posts

Showing posts from June, 2009

DateTime.Now in C#

DateTime Class is used to get the various possibilities that can be included within a day, month or a year. I am going to discuss about some functionalities of DateTime.Now here. For example: To get the current date and time, use DateTime.Now which gives us 6/24/2009 9:45:00 AM DateTime.Now has 5 important functions to get date and time in different formats. 1) DateTime.Now.ToLongDateString() - Displays in the format "Wednesday, June 24, 2009." 2) DateTime.Now.ToLongTimeString() - Displays in the format "12:00:00 AM. " 3) DateTime.Now.ToShortDateString() - Displays in the format "6/24/2009" 4) DateTime.Now.ToShortTimeString() - Displays in the format "12:00 AM" 5) DateTime.Now.ToString("Format") - This method accepts different formats. The formats can be obtained from GetDateTimeFormats() method of DateTime.Now and has 133 different formats that anyone can think of while displaying Date and Time. For example: DateTime.Now.ToString(...