Code
C#.NET
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("With Seconds" + "<br />");
Response.Write("12 Hour Date Format : " + DateTime.Now.ToString("hh:mm:ss tt") + "<br />");
Response.Write("24 Hour Date Format : " + DateTime.Now.ToString("HH:mm:ss tt") + "<br />");
Response.Write("Without Seconds" + "<br />");
Response.Write("12 Hour Date Format : " + DateTime.Now.ToString("hh:mm tt") + "<br />");
Response.Write("24 Hour Date Format : " + DateTime.Now.ToString("HH:mm tt") + "<br />");
}
VB.NET
Protected Sub Page_Load(sender As Object, e As EventArgs)
Response.Write("With Seconds" & "<br />")
Response.Write("12 Hour Date Format : " & DateTime.Now.ToString("hh:mm:ss tt") & "<br />")
Response.Write("24 Hour Date Format : " & DateTime.Now.ToString("HH:mm:ss tt") & "<br />")
Response.Write("Without Seconds" & "<br />")
Response.Write("12 Hour Date Format : " & DateTime.Now.ToString("hh:mm tt") & "<br />")
Response.Write("24 Hour Date Format : " & DateTime.Now.ToString("HH:mm tt") & "<br />")
End Sub
Output
With Seconds
12 Hour Date Format : 03:01:31 PM
24 Hour Date Format : 15:01:31 PM
Without Seconds
12 Hour Date Format : 03:01 PM
24 Hour Date Format : 15:01 PM
Further Reading
Custom Date and Time Format Strings[
^]