I think the Anytime datetimepicker widget is the cat's meow (or the Rolls Royce's roar (Why are the key elements of the anytime jQuery plugin blending in with the background/invisiblized?)),
I implement it this way:
HTML
<label for="BeginDateTime" class="staticLabel">Begin Date Range</label>
<input id="BeginDateTime" name="BeginDateTime" required="true" />
jQuery
AnyTime.picker("BeginDateTime");
var d8 = new Date();
d8.setHours(0);
d8.setMinutes(0);
d8.setSeconds(0);
$('#BeginDateTime').val(d8);
...but, although setting the time to zilch/midnight works (sort of) at first:
(actually, I just want the date and time, not the GMT jazz, etc.)
...when I mash the input element to invoke/drop down the AnyTime widget, it forgets that it was set to zilch, and over[rid,writ]es that with the current time:
How can I get the AnyTime widget to preserve the value I assign it when it is dropped down (until when and if the user changes it explicitly, of course)?
I also tried this:
$( "#BeginDateTime" ).click(function() {
var d = new Date();
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
$('#BeginDateTime').val(d);
});
...but the only difference was that no val appears in the input element until I click on it - it still shows zilch, but drops down the current time...
I tried this, too:
AnyTime.picker("BeginDateTime",
{ labelHour: "00",
labelMinute: "00",
labelSecond: "00"
});
...but it seems to do nothing.
AMA's answer worked like a charm. This code:
AnyTime.picker("BeginDateTime");
// Set the initial time to midnight
var convFrom = new AnyTime.Converter();
var d8From = new Date();
d8From.setHours(0);
d8From.setMinutes(0);
d8From.setSeconds(0);
$('#BeginDateTime').val(convFrom.format(d8From));
AnyTime.picker("EndDateTime");
// Set the initial time to the second before midnight
var convTo = new AnyTime.Converter();
var d8To = new Date();
d8To.setHours(23);
d8To.setMinutes(59);
d8To.setSeconds(59);
$('#EndDateTime').val(convTo.format(d8To));
...resulted in this:
The picker automatically parses the initial value from the input field, but it must be in the correct format. The easiest way to set the value is to use AnyTime.Converter, for example:
var conv = new AnyTime.Converter();
var d8 = new Date();
d8.setHours(0);
d8.setMinutes(0);
d8.setSeconds(0);
$('#BeginDateTime').val( conv.format(d8) );