出现这种问题的原因可能是时区设置错误或者时间戳未被正确处理。为了解决这个问题,可以尝试以下几个步骤:
const currentDate = new Date().toLocaleString("en-US", { timeZone: "Asia/Taipei" });
const timestamp = new Date(currentDate).getTime();
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'; import { MatDatepickerInputEvent } from '@angular/material';
export const VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DatepickerValueAccessor), multi: true };
@Component({
selector: 'datepicker-value-accessor',
providers: [VALUE_ACCESSOR],
template:
})
export class DatepickerValueAccessor implements ControlValueAccessor{
// Initialization of variables date: any; onTouched: () => void; onChange: (_: any) => void;
// Writes a new value to the element writeValue(value: any) { this.date = value; }
// Registers a callback function that should be called when the control's value changes in the UI registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }
// Fires when the control is blurred registerOnTouched(fn: () => void): void { this.onTouched = fn; } }
dateFormat="yyyy-MM-dd" dateFormat="MM/dd/yyyy" dateFormat="dd/MM/yyyy"
通过以上步骤,可以