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 7852251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:22:37+00:00 2026-06-02T19:22:37+00:00

I am trying to convert DateTime object to string using formatting but due to

  • 0

I am trying to convert DateTime object to string using formatting but due to some strange reason, it ignores AM/PM. It would just take the magnitude of the Hour in the object.

I am using the following format:

StartDate.ToString("yyyy-MM-dd hh:mm:ss.fff");

and

String.Format("0:yyyy-MM-dd hh:mm:ss.fff", StartDate);

I don’t think that there is a difference between the two, but just wanted to give it a try. If I pass a value 4/28/2012 6:00:00 AM or 4/28/2012 6:00:00 PM, the result is the same “2012-04-27 06:00:00.000”

  • 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-06-02T19:22:38+00:00Added an answer on June 2, 2026 at 7:22 pm

    You’ve used hh which uses the 12-hour clock. You want HH which uses the 24-hour clock.

    See MSDN for more details about custom format strings.

    Note that you may wish to specify the invariant culture, unless you really want the time separator to depend on the current culture:

    string formatted = StartDate.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                          CultureInfo.InvariantCulture);
    

    (Note that you shouldn’t have the braces if you’re passing the format string to ToString. I’ll assume this was just a typo in the question.)

    If you want to use the 12-hour clock, use tt in the format string to produce the AM/PM designator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert a string from to a Joda DateTime object. The date
I am trying to convert an access datetime field to a mysdl format, using
Am just trying to understand why this exception throws. Cannot implicitly convert type 'System.DateTime?'
How can I convert a string 08:00 to a DateTime datatype? Im trying to
I'm trying to write some code to convert data from a object type field
How can I convert a datetime object to the format yyyy/MM/dd? I am trying
I'm trying to create a string from the DateTime object which yields the format
I am trying to convert a date to a DateTime Object. My code works
I'm trying to convert JSON to C# object using Json.NET. The object looks like
I am trying to convert all DateTime values in a DataTable to strings. Here

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.