我找到了我与时区斗争的原因。缩写的AEDT不是Moment.tz的可接受值。AEDT可以表示多个时区。例如,美国东部,澳大利亚东部等等只是改变
momentTZDate.tz("AEDT");
到
momentTZDate.tz("Australia/Brisbane");
解决了我的问题。下面是我的
typescript
我用来解决这个问题的代码。我不会说这是最好的,但它是有效的。
private getCalDate(date:number, time: string): Date {
// create an object in which the hours and minutes can be parse from(do to free text entry on the backend moment handles different inputs)
let timeFormatter = new Date();
timeFormatter.setMilliseconds(date);
let momentHrMin = moment(timeFormatter.toDateString() + " " + time);
//WP sever is on GMT get the day, month and yr
let momentTZDate = momentTz.unix(date);
momentTZDate.tz('GMT');
let day = momentTZDate.days();
let month = momentTZDate.month();
let yr = momentTZDate.year();
//set the correct timezone on the ecpoh/unix DATE with momentTz.
momentTZDate.tz("Australia/Brisbane");
// Lastly set the date so the timezone conversions are correct
momentTZDate.set(
{
day: day,
month: month,
year: yr,
hour: momentHrMin.hour(),
minute: momentHrMin.minute(),
second: 0,
millisecond: 0
}
);
return momentTZDate.toDate();
}