Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3680028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:31:42+00:00 2026-05-19T03:31:42+00:00

I want to display a date with this format : MM/dd/yyyy HH:mm:ss tt for

  • 0

I want to display a date with this format :

  • MM/dd/yyyy HH:mm:ss tt

for example :

  • 01/04/2011 03:34:03 PM

but I have a problem with the following code

class Program
{
    static void Main(string[] args)
    {
        DateTime dt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0);
        string displayedDate = dt.ToString("MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
        Console.WriteLine(displayedDate);
        Console.Read();
    }
}

displays :

01/04/2011 12:00:00 AM

instead of

01/04/2011 00:00:00 AM

Anyone knows why ?

Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:31:43+00:00Added an answer on May 19, 2026 at 3:31 am

    Because you’ve specified a 12-hour clock format instead of a 24-hour format.

    The documentation for the DateTime.ToString method gives a full table of format specifiers and what they mean. The choices for hour are as follows:

    "h"     The hour, using a 12-hour clock from 1 to 12.
    "hh"    The hour, using a 12-hour clock from 01 to 12.
    "H"     The hour, using a 24-hour clock from 0 to 23.
    "HH"    The hour, using a 24-hour clock from 00 to 23.
    

    So, instead of the hh custom format specifier, you need to use HH. Change this line:

    string displayedDate = dt.ToString("MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
    

    to this:

    string displayedDate = dt.ToString("MM/dd/yyyy HH:mm:ss tt", CultureInfo.InvariantCulture);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to display the current date in this format Wednesday march 28,2012 ,
In my application I want to display the date in this format: 21st Aug,2012
I have the following code =IIf(Fields!Freeze.Value, Fields!effectivedate.Value, IIF(Month(Fields!effectivedate.Value) <> Month(Now()), Format(Now(), MM/dd/yyyy) , Fields!effectivedate.Value))
I want to display date like this in my website Wednesday, March 03, 2010
Using VB.NET I want to display the date in datetimepicker from the database. Code.
I know how to get a current date. but I want it to display
I want to format a date object so that I can display strings such
I have a date array sorted in asc order. I want to display the
Hello I want to display current date. I trying do it like this: calendar
I know of date formats such as yyyy-mm-dd -which displays date in format 2011-02-26

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.