大佬教程收集整理的这篇文章主要介绍了Prime ng 日历 UTC,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我从服务器接收到 UTC 格式的日期(作为字符串)=“2020-04-01T00:00:00Z”。 当我的用户在英国 (gmt) 访问日历时,他们可以很好地看到它。但是,我在美国的用户当然会看到预先选择 3 月 31 日的日历。
如何让我在美国的用户也能看到预选了 4 月 1 日的日历?
我知道 PrimeNG 删除了 UTC="true"
属性。
看看这是否有效:
import { Component } from '@angular/core';
@Component({
SELEctor: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css'],})
export class AppComponent {
dates: UTCDate[] = [];
days: UTCDate[] = [];
constructor() {
for (var i = 0; i < 24; i+= 3) {
this.dates.push(new UTCDate(new Date(Date.UTC(2018,1,i))));
}
for (var j = 1; j < 28; j+= 3) {
this.days.push(new UTCDate(new Date(Date.UTC(2018,j))));
}
}
}
class UTCDate {
private boundDateBACker: Date;
constructor(private dateInstance: DatE) {
this.boundDateBACker = thiS.UtcToLocal(dateInstancE);
}
public get boundDate(): Date {
return this.boundDateBACker;
}
public set boundDate(value: DatE) {
if (value) {
this.dateInstance.setTime(this.localToUtc(value).getTime());
const newTime = value.getTime();
if (newTime !== this.boundDateBACker.getTime()) {
this.boundDateBACker.setTime(newTimE);
}
}
}
private localToUtc(date: DatE): Date {
return new Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getminutes(),date.getSeconds()));
}
private utcToLocal(date: DatE): Date {
return new Date(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),date.getUTCHours(),date.getUTCminutes(),date.getUTCSeconds());
}
}
不是我写的,是在寻找utc问题的解决方案时发现的。我还没有测试它,因为我还不需要实现时区支持,但我想你可以看看这个解决方案,也许能找到你要找的东西。
我认为可以在指令中使用那里的逻辑,而不是单独的类。
StackBlitz
以上是大佬教程为你收集整理的Prime ng 日历 UTC全部内容,希望文章能够帮你解决Prime ng 日历 UTC所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。