首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何转换此卡片使其在角度材质中看起来很好< DateTime -DateTime-subtitle>

如何转换此卡片使其在角度材质中看起来很好< DateTime -DateTime-subtitle>
EN

Stack Overflow用户
提问于 2019-06-20 03:01:26
回答 1查看 74关注 0票数 1

我有一个日期看起来像这样

2000-12-16T00:00:00

当我在这个物料代码中显示它时:(它是publish_date)

代码语言:javascript
复制
<mat-card *ngFor="let book of bookItems">

  <mat-card-header >
    <mat-card-title>{{book.title | titlecase}}</mat-card-title>
    <mat-card-subtitle>{{book.description}}</mat-card-subtitle>
    <mat-card-subtitle>{{book.author}}</mat-card-subtitle>
    <mat-card-subtitle>{{book.genre}}</mat-card-subtitle>
    <mat-card-subtitle>{{book.publish_date}}</mat-card-subtitle>
    <mat-card-subtitle>{{book.price}}</mat-card-subtitle>

  </mat-card-header>

</mat-card>

我如何将它转换成更好、更人性化的东西?

日期来自xml文件,如下所示:

代码语言:javascript
复制
  <book id="B1">
    <author>Kutner, Joe</author>
    <title>Deploying with JRuby</title>
    <genre>Computer</genre>
    <price>33.00</price>
    <publish_date>2012-08-15</publish_date>
    <description>Deploying with JRuby is the missing link between enjoying JRuby and using it in the real world to build high-performance, scalable applications.</description>
  </book>

它是这样读入的:(这是Publish_date )

代码语言:javascript
复制
[HttpGet]
public IActionResult GetBookItems()
{
    List<BookItem> BookItems = new List<BookItem>();
    XDocument doc = _db.GetXmlDb();
    List<BookItem> bookitems = doc.Descendants("book").Select(x => new BookItem()
    {
        Id = (string)x.Attribute("id"),
        Author = (string)x.Element("author"),
        Title = (string)x.Element("title"),
        Genre = (string)x.Element("genre"),
        Price = (decimal)x.Element("price"),
        Publish_date = (DateTime)x.Element("publish_date"),
        Description = (string)x.Element("description")
    }).ToList();
    return Ok(bookitems);
}

这基本上是一个来自Angular应用程序的Crud调用,上面的代码是ASP.NET Controller

当我在Angular应用程序中收到bookItem时,如何让它变得更好。这是Angular应用程序书籍

代码语言:javascript
复制
export interface BookItem
{
  id: string;
  author: string;
  title: string;
  genre: string;
  price: string;
  publish_date: string;
  description: string;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-20 03:23:00

代码语言:javascript
复制
new Date('2000-12-16T00:00:00');

然后,在需要使用DatePipe<mat-card-subtitle>上,您可以使用pre-defined formats

代码语言:javascript
复制
<mat-card-subtitle>{{ book.publish_date | date: long }}</mat-card-subtitle>

代码语言:javascript
复制
<mat-card-subtitle>{{book.publish_date | date: 'dd MMMM yyyy' }}</mat-card-subtitle>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56674259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档