Base solution for your next web application
Open Closed

datetimepicker changing time when I format is LT #9254


User avatar
0
marble68 created

I have an input with a DateTime.

Looking at raw source, what comes down is correct

6/23/2020 9:00:00 AM

In the createoredit.js, there is:

      $('.date-picker').datetimepicker({
            locale: abp.localization.currentLanguage.name,
            format: 'L'

        });

by default.

If I set format to 'L LT' is displays correctly.

If I set format to LT, it changes the time to "6:00 AM".

The only way I can get the correct time to show is to format my DateTime with .ToString("t")

Is this something I'm doing wrong?

Thanks for any advice.


9 Answer(s)
  • User Avatar
    0
    marble68 created

    For what it's worth - here's how I'm having to address it:

        $('.date-picker').each(function (i, e) {
            $(e).val(moment($(e)[0].defaultValue).format("HH:mm A"));
        })
    

    Is this the normal way it's handled?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you check the value of moment().tz() by executing it on the browser console ? If you are using TimeZones, moment might be changing your date to active timezone.

  • User Avatar
    0
    marble68 created

    I did - It is correct, both the IANA and TimeZoneInfo.

    Like I said, If I change the formatting to include the date along with it, it shows the correct time (format: 'L LT').

    But if I use only LT, the value is incorrect. It's 6:00 AM regardless of what the value in the input field is (I should clarrify - regardless of the input value. I haven't tested this by changing my local timezone.)

    In the cshtml, if I formatted the datetime to "t" (putting only the time in the input value) it would show the correct time.

    Right now - I'm having to set that value via the above; which is fine - but not expected.

  • User Avatar
    0
    marble68 created

    Of note - my local time zone is CST, which is -6 hours offset from UTC, yet it's showing 6 AM. We're in Daylight savings, so currently it's -5 hours.

    If it were somehow parsing incorrectly, and getting midnight UTC, you'd think it'd get 7PM or 6PM.

    I'll test this further and see where 6:00 AM is coming from.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @marble68

    Could you also share how do you set the value of datet picker ? So we can also test it.

  • User Avatar
    0
    marble68 created

    Certainly.

    On my viewModel, I have something like: public DateTime SundayStartUTC { get; set; }

    In the view, I set it as follows:

                                    <div class="form-group position-relative">
                                        <label for="CompanyDefault_SundayStartUTC">@L("SundayStartUTC")</label>
                                        <input class="form-control m-input date-picker" id="CompanyDefault_SundayStartUTC" type="text" name="sundayStartUTC" value="@Model.CompanyDefault.SundayStartUTC" />
                                    </div>
    

    In javascript, I set it as such:

        $('.date-picker').datetimepicker({
            locale: abp.localization.currentLanguage.name,
            format: 'LT'
        });
        
    

    I'm doing anything too crazy, I don't think?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @marble68,

    Is it possible to share your project via email with [email protected] ?

    Thanks,

  • User Avatar
    0
    marble68 created

    Quick update - I've think I've addressed this by using .ToString("s") for these fields.

    It appears moment's parsing is to blame.

    I'll let you know.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @marble68 Thanks, I will also try to find the problem.