【发布时间】:2017-05-17 11:13:41
【问题描述】:
好的,这个问题已被问到here,但是给出的解决方案似乎无法解决我的问题。
当我点击保存时,我会参考这些字段并创建一个日期,如下所示:
this.profile.date_of_birth = new Date(this.editProfileForm.value['year'], this.editProfileForm.value['month'], this.editProfileForm.value['day']);
登录到控制台时显示:
1988 年 12 月 23 日星期五 00:00:00 GMT+1100 (AEDT)
然后我调用在http://localhost:3005 上运行的nodejs 应用程序,该应用程序获取数据并将其保存到mongodb,在保存之前我记录了 date_of_birth 的值,如下所示:
api.put('/update', authenticate, (req, res) => {
console.log(req.body.date_of_birth);
// Save properties
});
但是这会记录:
1988-12-22T13:00:00.000Z
今天是休息日……
当用户按下保存时,在创建新日期之前我没有进行任何格式化,所以我不确定为什么当它离开前端应用程序并进入后端应用程序时,日期显示不正确...... .
nodejs 应用程序的实际调用在这里:
saveProfile(profileId: string, token: string, profile: Profile): Observable<any> {
var body = {
"id": profile.id,
"date_of_birth": profile.date_of_birth,
}
return this.http.put(UPDATE_EDIT_PROFILE, body, {
headers: this.setHeaders(token)
}).map((res: any) => res.json());
}
谁能推荐可能出错的地方?
【问题讨论】:
标签: node.js mongodb angular date typescript