将横幅广告设置在预期的时区

时间:2019-10-01 03:21:18

标签: angular timezone

试图在世界范围内设置相同的横幅,但未获得预期的结果。

在我的项目中,我想设置一个带有一些开始日期和结束日期的中断横幅。目前,我正在将系统日期与开始日期和结束日期进行比较,并相应地显示横幅。这里的问题是不同的时区。为了进行同步,我将所有3个日期(开始,sysDate和结束日期)转换为UTC,但在CST时区不起作用。

let startDate, endDate;
let sysDate = new Date();
this.sysDate= new Date(this.sysDate.toUTCString()).valueOf();
this.startDate = new Date(this.OutageDetails.startDate);
this.startDate= new Date(this.startDate.toUTCString()).valueOf();
this.endDate= new Date(this.OutageDetails.endDate);
this.endDate= new Date(this.endDate.toUTCString()).valueOf();
if(startDate<= this.sysDate && this.sysDate<=this.endDate())
{
  console.log('Show the banner');
}

///在这里,OutageDetails是我在其中获取startDate和endDate的文件

这显示了所有UTC区域而不是CST的预期结果。我也尝试了GMT,但没有成功。请让我知道最佳解决方案。

1 个答案:

答案 0 :(得分:-1)

请参考这两个网址以获得更好的解决方案: 1)https://momentjs.com/ 2)https://momentjs.com/timezone/