Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 新日期总是迟1天返回_Angularjs_Date_Servicenow - Fatal编程技术网

Angularjs 新日期总是迟1天返回

Angularjs 新日期总是迟1天返回,angularjs,date,servicenow,Angularjs,Date,Servicenow,我为new Date()编写了以下代码,以及一个将new Date()格式化为更易于理解的函数: data.onbCase.push({ first_name: onbCase.getDisplayValue('subject_person.first_name'), last_name: onbCase.getDisplayValue('subject_person.last_name'),

我为new Date()编写了以下代码,以及一个将new Date()格式化为更易于理解的函数:

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>

但这似乎不正确……有什么建议吗?

有关更多信息,请参阅此问题:

new Date()
字符串解析器不可靠,因为不同的字符串日期格式会得到不同的结果

new Date()
// Fri Feb 15 2019 15:08:14 GMT-0600 (Central Standard Time)

new Date("2019-02-15")
// Thu Feb 14 2019 18:00:00 GMT-0600 (Central Standard Time)

new Date("2019-02-15 00:00:00")
// Thu Feb 15 2019 18:00:00 GMT-0600 (Central Standard Time)

new Date("02/15/2019")
// Fri Feb 15 2019 00:00:00 GMT-0600 (Central Standard Time)
某些日期格式,特别是如果您不包含时间信息,会将您的日期视为源自格林威治标准时间,然后根据计算机的区域设置对日期进行偏移。这将导致日期被负6小时(CST)抵消,有效地将您的一天更改为前一天

new Date()
// Fri Feb 15 2019 15:08:14 GMT-0600 (Central Standard Time)

new Date("2019-02-15")
// Thu Feb 14 2019 18:00:00 GMT-0600 (Central Standard Time)

new Date("2019-02-15 00:00:00")
// Thu Feb 15 2019 18:00:00 GMT-0600 (Central Standard Time)

new Date("02/15/2019")
// Fri Feb 15 2019 00:00:00 GMT-0600 (Central Standard Time)