datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Time changing between AM/PM when clicking into the field

Open THEFID101 opened this issue 8 years ago • 9 comments

Everything works as expected, however I have an issue that is perplexing me... When I click into the date field and then click out without changing/clicking the time, It changes the PM into AM. When the time is noon, it will add 12 hours and change to the next day in the field.

JQuery version: 1.12.4

DateTimePicker Version (from the JS file):

  • @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2015
  • @version 1.3.3

HTML:

Script: $('#Start').datetimepicker({ formatTime: 'h:i A', formatDate: 'd.m.Y', format: 'm/d/Y h:i A', step: 30 });

THEFID101 avatar Feb 14 '17 19:02 THEFID101

Also experiencing this issue.

scottmetoyer avatar Mar 08 '17 17:03 scottmetoyer

I'm encountering the same issue. Here's the code I'm using:

if(!$("##meetingPicker").prop("readonly")) {
    $('##meetingPicker').datetimepicker({
        formatTime:'g:i A',
        format: 'm/d/Y h:i A',
        step: 15,
        minDate: new Date(),
        startDate: new Date(),
        onSelectTime: function(current_time, $input) {
            parseStartDate($input.val());
        }
    });
}
function parseStartDate(dateTimeStr) {
    var regex = /(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{2}):(\d{2})\s+(AM|PM)/g;   /*RegEx to parse Date-Time selected*/
    var match = regex.exec(dateTimeStr);

    if(match != null && match.length == 7) {
        $("##hdnDay").val(match[2]);
        $("##hdnMonth").val(match[1]);
        $("##hdnYear").val(match[3]);
        $("##hdnTime").val(match[4]  + match[5]);
        $("##hdnAMPM").val(match[6]);
    }
}

I haven't dug into the source too deeply, but I'm guessing it has to do with formatter. In my experimentation if I removed "A" from the end of the format string so it wasn't displaying the AM/PM, it also wouldn't advance the day by 1 like it was when it was jumping forward 12 hours. It also only appears when I select a 12:XX value for the time. If I select 1:00, it has no problems.

Zaratuir avatar Mar 14 '17 23:03 Zaratuir

I'm experiencing the same issue. Any solutions?

ElColo avatar Aug 07 '17 22:08 ElColo

My solution was to use another datetime script.

THEFID101 avatar Aug 07 '17 22:08 THEFID101

+1

priscilapower avatar Oct 25 '17 13:10 priscilapower

This post is almost a year old, but here is how I solved it. Upgraded to the 2.5 version of jquery.datetimepicker.full.min.js and added "validateOnBlur: false"

.datetimepicker(
              {  minDate: 0, 
                 format:'m/d/Y h:i a', 
                 formatTime:'h:i a',
                 defaultTime:'8:00',
                 validateOnBlur: false,
                step:30
            });

kevinneibarger avatar Jun 28 '18 13:06 kevinneibarger

I have the same problem. I noticed it happens only when AM/PM mode is used and Hour 12 is selected (AM or PM) kevinneibarger 's solution worked for me. Thank you Kevin. Version upgrade is not necessary. validateOnBlur: false,

sukrub avatar Feb 25 '19 22:02 sukrub

sukrub, that doesn't solve the other 2 issues quoted here: https://github.com/xdan/datetimepicker/issues/657#issuecomment-383386369

PapillonUK avatar Feb 26 '19 14:02 PapillonUK

My solution was to use another datetime script.

I know this is five years later.. however I'd be curious and much appreciate if you'd share which datetime script you used in lieu of datetimepicker. Many thanks!

SeanDSpidle avatar Jul 26 '22 20:07 SeanDSpidle