Help setting time when letting user set the date

Hello,

How can I set the time while setting the date?
I have a working input with the <input id="datePicker" type="date"/> That lets the user set a date in html calendar. Then a button with myDate2() bind to it.
Relevant code:

$(document).ready( function() {
    var now = new Date();
 
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);

    var today = now.getFullYear()+"-"+(month)+"-"+(day);
    

   $('#datePicker').val(today);
   
});
function myDate2(){
  const d = new Date($('#datePicker').val())
  console.log(new Date($('#datePicker').val()))
  
viewer.clock.currentTime = new Cesium.JulianDate.fromDate(d);
}

This changes the date in the animation in the down left but the time is set to 00:00:00 UTC
How can I implement and html input type="time" to this function so the user also can set a specific time and not have to play through the animation till it reaches the desired time of the day.

I’ve tried setting up a sandcastle link, but I did not get it to work since i have jquery code here.

Thanks in advance!

Hi @Albnas, you could construct the Javascript Date with a combination of the two inputs:

  const d = new Date($('#datePicker').val() + $('#timePicker').val());

I haven’t tested this code—you would need to verify the combined string is in a valid format.

But I think it might be easier to use the datetime-local input type, to get both date and time from one element.

Hi @jjhembd , thanks for your reply, datetime-local was the way to go here.

Thanks