Find current time in C#

Home Forums General Programming C# Find current time in C#

This topic contains 0 replies, has 1 voice, and was last updated by  Hirendra Sisodiya 6 years, 6 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3619

    If you want to get only current time not datetime in C# then you can try the following ways:

    For short time pattern:

    DateTime.Now.ToShortTimeString();
    Output: 2:47 PM

    DateTime.Now.ToString(“t”);
    Output: 2:47 PM

    DateTime.Now.ToString(“hh:mm tt”);
    Output: 02:47 PM

    For Long time pattern:

    DateTime.Now.ToLongTimeString();
    Output: 2:47:26 PM

    DateTime.Now.ToString(“T”);
    Output: 2:47:37 PM

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.