Skip to content

Instantly share code, notes, and snippets.

@brandanmajeske
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandanmajeske/3defa81c098fb17f5c02 to your computer and use it in GitHub Desktop.
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
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');
};
}
]);
@brandanmajeske
Copy link
Author

usage: {{details.datetomodify | adjustDatepicker}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment