2

Control is an input field that I define. Whenever I click on the control, it will open the datetimepicker and append whatever date I choose onto the control for example 11/30/2015 ( Display value )

Javascript

control.datetimepicker({
    pickTime:false,
    language: en
});

Is there a way that I could obtain raw date (correct me if I am wrong) like this:

Wed Feb 06 2013 00:00:00 GMT+0800 (Malay Peninsula Standard Time)

As different language will have different display date value, it will be great if I am able to obtain raw date to do processing into my server.

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
specialone
  • 130
  • 8

2 Answers2

1

I had found the answer in here: Bootstrap 3 datetimepicker events not firing up

The version I use is: http://eonasdan.github.io/bootstrap-datetimepicker/

Therefore to get the date obj stuff I can use this:

control.datetimepicker({
     pickTime: false,
     language: en
  }).on("dp.change", function(e) {
  var date = e.date, 
  dDate = date._d, // e.g Wed Feb 06 2013 00:00:00 GMT+0800 (Malay Peninsula Standard Time 
  dateFormat = date._f; // e.g MM-DD-YYYY
  // Append to attribute
  control.attr('dateFormat', dateFormat);
});

I can then use moment.js to format it like this:

value = $('#' + fieldDefinition.Name).val();
var dateFormat = $('#' + fieldDefinition.Name).attr('dateformat');
value = moment(value, dateFormat).format('YYYY-MM-DD');
// OR - Depending on what your server accept
value = moment(value, dateFormat).format();

Therefore I can display different date/datetime format/separator according to locale on my controls and also ensuring that they are formatted to the whatever I want. In my case is XML date / datetime format.

Community
  • 1
  • 1
specialone
  • 130
  • 8
0

EDIT $("selectorForDP").data().DateTimePicker.date()._d;

this is exactly what you are looking for.

suish
  • 3,253
  • 1
  • 15
  • 34
  • Keep in mind this will most likely only work for english formatted date. – Jonathan Feb 23 '15 at 06:59
  • @rouby it works as long as he does not change format explicitly via datetimepicker's option. – suish Feb 23 '15 at 07:08
  • More or less what I said.. ? – Jonathan Feb 23 '15 at 07:10
  • @Rouby I am looking for a way that can work for all kinds of locale display date. Which means if in US MM/DD/YYYY or Dutch DD-MM-YYYY should be able to return the date object/raw data. Thanks anyway. – specialone Feb 23 '15 at 07:10
  • @Rouby Yes. I found the solution for the control and yes I am also using [momentjs.com](http://momentjs.com). I posted an answer for this. Thanks mate for your help. – specialone Feb 23 '15 at 10:05