To format a date in the mentioned format, we can use the ToString
method of the DateTime
object and pass the appropriate format string. Here's an example:
main.cs197 chars4 lines
In the format string,
"MMMM"
represents the full month name"dd"
represents the day of the month with leading zeros"yyyy"
represents the year with four digits"hh"
represents the hour in 12-hour format with leading zeros"mm"
represents the minutes with leading zeros"ss"
represents the seconds with leading zeros"tt"
represents the AM/PM designatorBy passing this format string, we can get the desired output.
gistlibby LogSnag