javascript - Angular Bootstrap DatePicker UTC wrong output -


hello using angular datepicker in application working how supposed be. try working utc time , datepicker inited value:

scope.model.value = moment.utc().startof('day').todate() 

this result in date:

tue oct 27 2015 01:00:00 gmt+0100 (mitteleuropäische zeit) 

if want choose date e.g.: 1st june 2016 result of scope.model.value is:

"2016-05-31t23:00:00.000z" 

why datepicker changing date object format? how can take care off output format? , why date 31st may when selecting 1st june?

i have tried several approaches removing utc time information. example: (https://gist.github.com/weberste/354a3f0a9ea58e0ea0de):

(function () { 'use strict';  angular .module('myapp') .directive('datepickerlocaldate', ['$parse', function ($parse) {   var directive = {     restrict: 'a',     require: ['ngmodel'],     link: link   };   return directive;    function link(scope, element, attr, ctrls) {     var ngmodelcontroller = ctrls[0];      // called javascript date object when picked datepicker     ngmodelcontroller.$parsers.push(function (viewvalue) {       // undo timezone adjustment did during formatting       viewvalue.setminutes(viewvalue.getminutes() - viewvalue.gettimezoneoffset());       // want local date in iso format       return viewvalue;     });      // called 'yyyy-mm-dd' string format     ngmodelcontroller.$formatters.push(function (modelvalue) {       if (!modelvalue) {         return undefined;       }       // date constructor apply timezone deviations utc (i.e. if locale behind utc 'dt' 1 day behind)       var dt = new date(modelvalue);       // 'undo' timezone offset again (so end on original date again)       dt.setminutes(dt.getminutes() + dt.gettimezoneoffset());       return dt;     });   } }]) }) 

for coriuos here snippet how using picker:

<datepicker datepicker-localdate ng-model="model.value" min-date="mindate"></datepicker> 

maybe can help!

in app config can tell globally how want dapicker output format be. eg :

datepickerpopupconfig.datepickerpopup = 'dd/mm/yyyy'; 

doc here: angular boostrap datepicker doc

given app name "myapp":

angular.module('myapp', [     'ui.bootstrap' ]) .config(function(         datepickerpopupconfig     ) {          datepickerpopupconfig.datepickerpopup = 'dd/mm/yyyy';      } ); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -