FormatDateTime DateTime(?)

.FormatDateTime()

Formats a date and time as a long string in the form "d MMM yyyy H:mm(:ss)" ie: 1 Oct 2010 9:45:04 with optional seconds.

Method

public static string FormatDateTime(this DateTime dt, bool showSec = true)
public static string FormatDateTime(this DateTime? dt, bool showSec = true)
DateTime(?) dt

DateTime or DateTime? value to convert into the string format "d MMM yyyy H:mm(:ss)".

bool showSec
Default: true

Optionally removes the seconds from the display to show only minutes in the format "d MMM yyyy H:mm" ie: 1 Oct 2010 9:45.

Example

C#
string now = DateTime.Now.FormatDateTime();