0

Im using AnyTime picker to get date and time (start date& time) in a format "%d/%m/%Y %H:%i:%s", im trying to get this input to be converted into a date object so that i could use getSeconds() to get the seconds and add a duration(in seconds) to get the end time and date.

How can i convert this input?

<input id="chooseTime" name="chooseTime" type="text" maxlength="16" size="20" value="">



var anytimeFormat = "%d/%m/%Y %H:%i:%s";
AnyTime.picker( "chooseTime", { 
     format: anytimeFormat, 
     firstDOW: 1
 });


var schedule_start_time = new Date($("#chooseTime").val());
var schedule_end_time = new Date();
schedule_end_time.setSeconds(schedule_start_time.getSeconds() + durationInSecs);

Basically the problem is that the input is always the current date and time on my computer. The AnyTime picker input that i selected doesnt work. Did i did something wrongly. I have a feeling its the way im converting the chooseTime to a new Date. How can i do it, need some help!

Azl
  • 5
  • 1
  • 5

1 Answers1

0

The picker always initializes from the date/time in the input field. If the value in the input field is not a valid date/time (or not in the format that you specify), it defaults to the current time. If the field is blank, that would be the case.

If you want a different starting date/time, then set the value of the field when you create it. You can use jQuery's .val() method or the DOM .value property. To be sure the value is the right format, use an AnyTime.Converter such as:

var anytimeFormat = "%d/%m/%Y %H:%i:%s"; $('#chooseTime').val( (new AnyTime.Converter( { format:anytimeFormat})).format( new Date(2014,11,2,0,0,0) ) ); AnyTime.picker( "chooseTime", { format: anytimeFormat, firstDOW: 1 });

For faster assistance, please use the contact form on the project website.

Andrew M. Andrews III
  • 1,989
  • 18
  • 23