I have the following code for new Date() along with a function that formats the new Date() to something a bit more digestible:
data.onbCase.push({
first_name: onbCase.getDisplayValue('subject_person.first_name'),
last_name: onbCase.getDisplayValue('subject_person.last_name'),
start_date: formatDate(new Date(onbCase.getDisplayValue('hr_profile.employment_start_date')))
});
function formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate(),
monthIndex = date.getMonth(),
year = date.getFullYear();
return new Date(monthNames[monthIndex].substr(0,3) + ' ' + day + ', ' + year);
}
<td ng-show="c.options.start_date" title="{{item.start_date}}">{{item.start_date | date:'mediumDate'}}</td>
However, this always returns a date that is one day behind the correct date. Can someone explain why this happens and how to fix it? I know I can simply add 1 to the getDate():
var day = date.getDate() +1;
This seems incorrect though...any advice?