Last active
August 29, 2015 14:10
-
-
Save brandanmajeske/3defa81c098fb17f5c02 to your computer and use it in GitHub Desktop.
Angular / Bootstrap UI Datepicker filter to fix UTC/Local Datetime 'off by one' issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.filter('adjustDatepicker', [ | |
'$filter', function($filter) { | |
var dateFilter = $filter('date'); | |
return function(dateToFix) { | |
var localDate, localTime, localOffset, adjustedDate; | |
if (dateToFix === null) | |
return null; | |
localDate = new Date(dateToFix); | |
localTime = localDate.getTime(); | |
localOffset = localDate.getTimezoneOffset() * 60000; | |
adjustedDate = new Date(localTime + localOffset); | |
return dateFilter(adjustedDate, 'MM/dd/yyyy'); | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: {{details.datetomodify | adjustDatepicker}}