Jacques Bronkhorst
Jacques Bronkhorst

Reputation: 1695

bootstrap3 Datetimepicker set TimePicker Value

I am using: https://eonasdan.github.io/bootstrap-datetimepicker/ to generate a Time Picker Using the following code:

console.log(now);
$(function () {
    $('#datetimepicker3').datetimepicker({
        useCurrent: true,
        format: 'HH:mm',
        defaultDate: now
    });

});

My now Value is calculated like this:

var now = moment().format('YYYY-MM-DD')+'T'+ '@ViewBag.End'+'.000';

The ViewBag.End provides me a time string from my SQL Server. The Value of now according to my console is:

But when I run the page I get the following: Time End according to Application It displays as 20:00. Any Ideas?

Upvotes: 0

Views: 897

Answers (2)

Jacques Bronkhorst
Jacques Bronkhorst

Reputation: 1695

I found a workaround. By changing my date picker declaration to include the following:

 $(function () {
    $('#datetimepicker3').datetimepicker({
        useCurrent: true,
        format: 'HH:mm'
    });
    $("#datetimepicker3").find("input").val('@ViewBag.End'); //This sets the value correctly
});

Upvotes: 1

Alden Be
Alden Be

Reputation: 517

I suspect it is pulling filling HH with the first two digits. 20 in this case, and MM with the first two digits after a colon 00 in this case. You will need to pass only the hour and minutes instead of now to defaultDate if you only want to display HH:MM

Upvotes: 0

Related Questions