Find current time in C#

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.