none
Windows Form weird Date time display RRS feed

  • Question

  • I have a form I created awhile ago. Today I noticed a DtaeTime Picker custom formatted field has a weird date time. The control is bound to a datetime field. The Custom format is "MM/dd/yyyy HH:mm tt". It is displaying the date as "08/02/2019 18:13 PM". I believe there is no 18 hour in Regular time format. Don't know how long its been is like this. Could there a property on the control that is causing this reaction. As far as I know this is the only control doing this.  




    Friday, November 15, 2019 8:12 PM

Answers

  • Hi,

    You wrote "MM/dd/yyyy HH:mm tt". 
    Capital letter "HH" means 24-hour clock. If you want to show 12-hour clock like "06:13 PM", please write "hh:mm tt". (use lower-case)

    Regards,


    Ashidacchi -- http://hokusosha.com

    • Proposed as answer by WayneAKing Monday, November 18, 2019 5:29 AM
    • Marked as answer by Seeker of Wisdom Monday, November 18, 2019 1:21 PM
    Friday, November 15, 2019 10:04 PM

All replies

  • Hi,

    You wrote "MM/dd/yyyy HH:mm tt". 
    Capital letter "HH" means 24-hour clock. If you want to show 12-hour clock like "06:13 PM", please write "hh:mm tt". (use lower-case)

    Regards,


    Ashidacchi -- http://hokusosha.com

    • Proposed as answer by WayneAKing Monday, November 18, 2019 5:29 AM
    • Marked as answer by Seeker of Wisdom Monday, November 18, 2019 1:21 PM
    Friday, November 15, 2019 10:04 PM
  • Date/Time gets edited in the BIOS,&/or R.click on the clock by the speaker in task bar,adjust date-time/internet time/edit/update..

    The other source,if its a desktop pc,the MB battery has failed,its a 2032 type.Simply power off pc/unplug/remove battery/wait 15 minutes or so,install new,power up pc.On pc start,enter the BIOS,reset date/time,edit for add-on hardware,save & exit.In windows,reset date time.

    Saturday, November 16, 2019 5:58 PM
  • Hi Seeker of Wisdom,

    As Ashidacchi said, you can modify "MM/dd/yyyy HH:mm tt" to "MM/dd/yyyy hh:mm tt".

    Here is my code you can refer to.

    private void Form1_Load(object sender, EventArgs e)
    {
          dateTimePicker1.Format = DateTimePickerFormat.Custom;
          dateTimePicker1.CustomFormat = "MM/dd/yyyy hh:mm tt";
    }

    Best Regards,

    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 18, 2019 3:14 AM
  • Thank you, I was not aware of that nuance of the date time format. I don't usually use caps except when it comes to minutes. Weird how one can look at a thing and just not see something like that. Again thank you.  
    Monday, November 18, 2019 1:21 PM