Angular UI datepicker gives me a converted UTC string. How to parse it back to local time, given the time difference?

I'm currently having problems with datepicker automatically changing time to UTC. Is there anything I can pass to datepicker so that it doesn't give me back the converted UTC string? For example, a user selects March 19 in a calendar, and the returned string will be something like this.

'2014-03-19T04:00:00.000Z' 

What I want β†’

 '2014-03-19T00:00:00-04:00' 

What I'm trying now (sort of hacking it) is trying to use the js moment to convert it back to the desired (expected) format, but I am having problems with this without hard subtraction coding. I want to be able to convert it from UTC back to local time.

Does anyone know about this solution using js or angular momentum?

+6
source share
2 answers

I ran into the same problem and used a filter that adjusts the date and time using local data to get around it:

 filter('adjustDatepicker', ['$filter', function($filter){ var dateFilter = $filter('date'); return function(dateToFix){ var localDate, localTime, localOffset, adjustedDate; localDate = new Date(dateToFix); localTime = localDate.getTime(); localOffset = localDate.getTimezoneOffset() * 60000; adjustedDate = new Date(localTime + localOffset); return dateFilter(adjustedDate, 'MM/dd/yyyy'); }; }]) 

Use it like this in the template file:

 {{details.datetomodify | adjustDatepicker}} 
+5
source

I think new Date('2014-03-19T04:00:00.000Z').toString() will provide you with a local version of UTC.

time

0
source

All Articles