You can configure DateTime object to show output in different ways as your need. You can easily fetch the System date and Time by using the following command
DateTime dateTime = DateTime.Now;
or you can create any custom date time object by using following command
DateTime newDateTime = new DateTime(2011, 3, 21, 10, 23, 12); // new DateTime(year, month, day, hr, min, sec)
Now if you just output any of this DateTime object on Console, it will give you output only in a single format which is dd-mm-yyyy hr:mm:ss AM/PM.
Now if you want to get output in some other format say just month name you want, or just want the name of day, or want to get output in the format dd month, yyyy. Then you can do so easily by just telling the .NET framework to format your output according to equivalent string (month or day or anything) you need.
You can download the full code from here. Click Here To Download
Here is the snapshot of output in Console of the sample code
Incoming search terms:
- if datetime is more recent c sharp (1)
- time format c# am pm (1)