Angular日历短日期格式不工作
创始人
2024-10-29 05:00:29
0

在组件中设置日期格式并在HTML中应用它

在组件中,在ngOnInit函数中使用以下代码设置日期格式:

import { formatDate } from '@angular/common';

export class MyComponent implements OnInit {
  // set the date format
  dateFormat: string = 'yyyy-MM-dd';

  ngOnInit() {
    // format your date to display it in the desired format
    const today = new Date();
    const formattedDate = formatDate(today, this.dateFormat, 'en-US');
    // use the formatted date
    console.log(formattedDate); // prints '2021-11-22'
  }
}

在HTML模板中使用Angular日期管道将日期格式化为短格式:

{{ myDate | date:'shortDate' }}

其中myDate是一个Date对象。这将以短格式(MM/dd/yyyy)显示日期。您也可以传递您自己的日期格式到管道中,就像这样:

{{ myDate | date:'yyyy/MM/dd' }}

这将以格式'yyyy/MM/dd'显示日期(例如2021/11/22)。

相关内容

热门资讯

近日!德州透视是真的假的,哥哥... 近日!德州透视是真的假的,哥哥打大a辅助,总是真的有辅助神器(哔哩哔哩)1、起透看视 德州透视是真的...
今日!hhpoker破解工具,... 今日!hhpoker破解工具,潮汕汇app辅助,其实有辅助方法(哔哩哔哩)1、实时潮汕汇app辅助透...
有玩家发现!pokemmo手机... 有玩家发现!pokemmo手机脚本辅助器,微乐兰州麻将小程序辅助,一直是真的有辅助攻略(哔哩哔哩)小...
昨日!wepoker透视版下载... 昨日!wepoker透视版下载,闲来辅助工具,确实是真的有辅助工具(哔哩哔哩)1、下载好闲来辅助工具...
有了最新消息!hhpoker有... 您好,杭州都莱到底有没有挂这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
为了进一步!pokeplus脚... 为了进一步!pokeplus脚本,邯郸胡乐辅助脚本下载,总是真的有辅助app(哔哩哔哩)1、邯郸胡乐...
目前来看!wepokerplu... 目前来看!wepokerplus作必弊,手机微乐小程序游戏破解器,原来存在有辅助软件(哔哩哔哩)1、...
据统计!aapoker透视脚本... 据统计!aapoker透视脚本下载,潮汕来物局开挂方法,总是是真的有辅助教程(哔哩哔哩)1、很好的工...
最终!wepoker永久免费脚... 最终!wepoker永久免费脚本,友聚哈局辅助,都是真的有辅助攻略(哔哩哔哩)1、不需要AI权限,帮...
据权威媒体报道!wejoker... 据权威媒体报道!wejoker辅助器要钱玩吗,九九联盟后台可以操作吗,一直真的有辅助软件(哔哩哔哩)...