Code for Time format in c# [Resolved]

Posted by Allemahesh under C# on 7/15/2013 | Points: 10 | Views : 1278 | Status : [Member] [MVP] | Replies : 6
I am using c#. I want to display only time in the below format.

HH-mm-ss tt.

Can any one help me.




Responses

Posted by: Prtkaggrwl on: 7/15/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Response.Write(DateTime.Now.ToString("HH-mm-ss tt"));

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ganeshjoshi on: 7/15/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
You can use this code

using System;
static void Main() {
DateTime dateTime = DateTime.Now;
Console.WriteLine ("T = {0:T}", dateTime ); // hh:mm:ss AM/PM
}

Hope this information is helpful to you...

Thanks
Regards,
ganesh joshi

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 7/15/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
But How I can use in my asp.net .cs file.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saclines on: 8/2/2013 [Member] Starter | Points: 25

Up
0
Down
Get the list of other formatting options here
http://www.dotnetlines.com/Blogs/tabid/85/EntryId/8/DateTime-ToString-Formats.aspx

Sachin N. S.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sudha29-23275 on: 8/2/2013 [Member] Starter | Points: 25

Up
0
Down
string time = DateTime.Now.ToString("HH:mm:ss tt");
Console.WriteLine(time);
Console.ReadKey();

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Veeru.5588 on: 8/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
use this code

using System;
static void Main()
{
DateTime dateTime = DateTime.Now;
Console.WriteLine ("T = {0:T}", dateTime ); // hh:mm:ss AM/PM
}

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response