【发布时间】:2017-12-25 07:20:37
【问题描述】:
我正在计算我的应用程序的日期,例如日期、周、月。
首先我定义日、周、月、自定义,例如:
this.reportTypes = [{TypeId: 1, Type: 'Day'}, {TypeId: 6, Type: 'Week'}, {TypeId: 30, Type: 'Month'}, {
TypeId: 10,
Type: 'Custom'
}]
接下来我定义的日期如下:
var currdate = new Date();
if(reportType==1){
// this.reportDataFromDate=currdate;
// this.reportDataToDate=currdate;
//This is for setting the current date
this.reportDataFromDate= currdate;
this.reportDataToDate= currdate;
}
else if(reportType==30){
var First = new Date(currdate.getFullYear(),currdate.getMonth(),1);
this.reportDataFromDate=First;
this.reportDataToDate=currdate;
}
else if(reportType!=10){
var last = new Date(currdate.getTime() - (reportType * 24 * 60 * 60 * 1000));
this.reportDataFromDate=last;
this.reportDataToDate=currdate;
}
}
问题是在选择reportType == 30之后,它必须得到当月的第一天。
它显示日期为1-Dec-2017,但它正在获取截至2017年11月30日的数据?
这是 SQL 服务器的屏幕截图。我将日期发送为 2017 年 12 月 1 日,但它正在 2017 年 11 月 30 日。
【问题讨论】:
-
你在哪个时区...别忘了,你在控制台看到的是UTC
-
@JaromandaX 在控制台中我看到了 2017 年 12 月 1 日的 IST
-
确实,抱歉,您在图片中显示的是 UTC(以为是一些控制台输出) - 所以,一切都很好
-
@JaromandaX 它是后端收到的数据/请求..
-
不管是什么,你的时区是 2017 年 12 月 1 日 0:0:0
标签: javascript angular datetime ionic-framework ionic2