stackoverflowuser:
You Can Use String.Format() Function Without ParseExtract() Function
VB.NET:-
Dim time As String = String.Format("{0:hh}:{0:mm} {0:tt}", Date.Now) '12:00 PM'
Dim time_1 As String = String.Format("{0:hh}:{0:mm}:{0:ss} {0:tt}", Date.Now) '12:00:25 PM'
Dim time_2 As String = String.Format("{0:mm}:{0:ss}.{0:fff}", Date.Now) '00:25.986 - Mostly Used In Stopwatches'
CSharp (C#):-
String time = String.Format("{0:hh}:{0:mm} {0:tt}", DateTime.Now); // 12:00 PM
String time_1 = String.Format("{0:hh}:{0:mm}:{0:ss} {0:tt}", DateTime.Now); // 12:00:25 PM
String time_2 = String.Format("{0:mm}:{0:ss}.{0:fff}", DateTime.Now); // 00:25.986 - Mostly Used In Stopwatches
Above Codes Are Examples, You Can Use Above Codes To Experiment/Observe/Make Applications With It
You Can Use Also In:
VB.NET:-
Label1.Text = String.Format("{0:hh}:{0:mm} {0:tt}", Date.Now) 'Display: 12:00 PM'
CSharp (C#):-
label1.Text = SString.Format("{0:hh}:{0:mm} {0:tt}", DateTime.Now); // Display: 12:00 PM
You Will Get The Formatted Timings In Any Label In Both VB.NET And C#