AngularMaterial日期选择器中日期不正确-日期为确切日期前一天。
创始人
2024-10-28 10:01:29
0

出现这种问题的原因可能是时区设置错误或者时间戳未被正确处理。为了解决这个问题,可以尝试以下几个步骤:

  1. 创建一个新的Date对象时传入所需的时区,例如:

const currentDate = new Date().toLocaleString("en-US", { timeZone: "Asia/Taipei" });

  1. 在组件中添加代码以将时间转换为时间戳:

const timestamp = new Date(currentDate).getTime();

  1. 在使用MatDatepicker模块时,使用ValueAccessor的提供程序来确保输入的正确性:

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; } }

  1. 最后,如果还存在问题,请确定日期格式正确。尝试使用以下选项之一将日期的格式化更改为所需的格式:

dateFormat="yyyy-MM-dd" dateFormat="MM/dd/yyyy" dateFormat="dd/MM/yyyy"

通过以上步骤,可以

相关内容

热门资讯

我来教大家!xpoker辅助怎... 我来教大家!xpoker辅助怎么用,德扑圈透视,一直存在有挂(有挂头条)1、每一步都需要思考,不同水...
重大通报!来玩德州破解器,we... 重大通报!来玩德州破解器,wepoker作弊视频,都是有挂(了解有挂)1、重大通报!来玩德州破解器,...
9分钟了解!德普之星透视免费,... 9分钟了解!德普之星透视免费,德扑圈有透视吗,好像有挂(有挂功能)1、玩家可以在透视最简单三个步骤对...
分享给玩家!pokermast... 分享给玩家!pokermaster辅助器,hhpoker可以开挂吗,一贯真的是有挂(有挂分享)1、有...
推荐攻略!德州局透视脚本,we... 推荐攻略!德州局透视脚本,wepoker看底牌,一直真的是有挂(有挂秘诀)1、透视辅助软件激活码多个...
玩家必看科普!poker ma... 玩家必看科普!poker master辅助,wepoker私局辅助,好像有挂(讲解有挂)该软件可以轻...
盘点一款!wpk显示有作弊,约... 盘点一款!wpk显示有作弊,约局吧是否有挂,好像存在有挂(有挂讲解)破解侠是真的助透视。每个模型中均...
一分钟带你了解!hhpkoer... 一分钟带你了解!hhpkoer辅助挂是真的吗,约局吧作弊脚本,原来有挂(有挂实锤)1、金币登录送、破...
玩家攻略推荐!sohoo竞技联... 玩家攻略推荐!sohoo竞技联盟辅助器,hhpoker作弊实战视频,都是真的是有挂(有挂存在)1、完...
盘点一款!wepoker有没有... 盘点一款!wepoker有没有插件,hhpoker德州挂真的有吗,好像真的是有挂(揭秘有挂)小薇(辅...