VB.Net Time Formats using ToString Function in ASP.Net

When you use VB.Net ToString function with DateTime variable in ASP.Net it allows you to specifiy the type of Time format you want to display on the ASP.Net web page. DateTime formats are the combination of few predefined set of characters that return the specified formats, the characters for Time Format specifier are H for 24 hours format style, h for 12 hours format style, m for minutes, s for seconds and tt for AM/PM. All these specifier characters are case sensitive.

 

Following are few examples of format specifiers that can be passed as a string to the VB.Net ToString Function to get desired form of time value:

 

You can try the following sample by specifying different date styles:

 

Enter Time:
Format Style Output
hh:mm : 04:58
hh:mm ss : 04:58 42
hh:mm ss tt : 04:58 42 PM
HH:mm ss tt : 16:58 42 PM
HHmm : 1658
MM-dd-yyyy HH:mm ss tt : 07-24-2014 16:58 42 PM
MM-dd-yyyy hh:mm ss tt : 07-24-2014 04:58 42 PM