Wednesday, 21 August 2013

Bootstrap datetime picker not working

Bootstrap datetime picker not working

I am using the http://www.malot.fr/bootstrap-datetimepicker/demo.php date
time picker for twitter bootsrap.
The requirement of the page that Im working on is that the users can
either use the date time picker or manually type in something and I
validate that the data is correct.
I am running into a few issues with this date time picker. First thing is
that it doesn't seem to work to date.js which would make date validation
very easy. Is there a setting or something out there that can make it work
with date.js?
Secondly, I am having a bit of trouble saving the value picked via the
date time picker.
So far I have tried 2 approaches :-
$('#dateTime').datetimepicker({
format: 'dd-M-yyyy HH:ii p',
autoclose: 1,
todayHighlight: 1,
startView: 2,
forceParse: 0,
showMeridian: 1
}).on('changeDate', function(ev) {
var date = ev.date;
//..Do stuff with the date
});
In this case I get a valid date, but the time isn't right. The date time
picker seems to assume the time is GMT. It grabs the time that was picked
and adds my time zone offset to it. (Im in EDT so it subtracts 4 hrs from
whatever I pick) Is there some sort of setting to prevent this conversion?
The second approach I tried was
var date = e.currentTarget.value;
//Do stuff with it.
In this I get the correct date time, but it cannot be saved to the
database because the format is invalid.
If I try to do
var isValid = new Date(date);
it return that the date isn't a valid date because the format that Im
using (dd-M-yyyy HH:ii p) isn't valid.
Note: I cannot change the format that is being displayed in the textbox.
I apologize if the question is confusing.

No comments:

Post a Comment