我有一个日期看起来像这样
2000-12-16T00:00:00
当我在这个物料代码中显示它时:(它是publish_date)
<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文件,如下所示:
<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 )
[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应用程序书籍
export interface BookItem
{
id: string;
author: string;
title: string;
genre: string;
price: string;
publish_date: string;
description: string;
}
发布于 2019-06-20 03:23:00
new Date('2000-12-16T00:00:00');
然后,在需要使用DatePipe
的<mat-card-subtitle>
上,您可以使用pre-defined formats
<mat-card-subtitle>{{ book.publish_date | date: long }}</mat-card-subtitle>
<mat-card-subtitle>{{book.publish_date | date: 'dd MMMM yyyy' }}</mat-card-subtitle>
https://stackoverflow.com/questions/56674259
复制相似问题