如何在Angular中将日期转换为可读形式,并同时连接两个日期? [英] How can I convert date to a readable form in Angular and also concatenate two dates?

查看:51
本文介绍了如何在Angular中将日期转换为可读形式,并同时连接两个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于任何事件,我都可以通过以下方式在html文件中获取日期:

 开始日期:2017-09-25T10:00:00结束日期:2017-09-25T11:00:00 

在我的控制器中,我将它们另存为:

  Event = {StartDate:开始,EndDate:结束} 

我正在寻找一种将它们连接到日期并进行修整的方法,以将其输出到我的html中.我的活动日期将始终是相同的,因此我希望显示以下内容:

  2017年9月9日,上午10点至上午11:00 

需要帮助!

解决方案

这是一个工作正常的插件,可以让您感觉到要使用的日期格式:

注意:您可以避免使用Angular的"longDate"来解析-"的左侧,但这会在当月的一天(例如,2017年9月20日与2017年9月20日)之间添加一个逗号./p>

查看文档以获得有关日期解析字符执行日期的详细信息什么.

For any event, Im getting dates in my html file in the following manner:

         Start Date: 2017-09-25T10:00:00 
         End Date:   2017-09-25T11:00:00 

In my Controller I have them saved as :

         Event= {StartDate: start, EndDate: end}

I am looking for a way to output them in my html with some concatenation and trimming done to the date. My event date will always be the same so I would like to be displayed something like:

              September 09 2017, 10 AM - 11:00 AM

Help Needed!

解决方案

Here's a working plunker that will give you a feel for the date formatting you're after: https://plnkr.co/edit/tmxQY9RyqGzHwCKhvQN0?p=preview

The template interpolation is key here

{{Event.StartDate | date:"MMMM dd yyyy ', ' h"}} {{Event.EndDate | date: "'-' h:mm a"}}

Note: you could save yourself from parsing the left side of the "-" with Angular's 'longDate', but that will add a comma after the day of the month (e.g. September 20, 2017 vs September 20 2017).

Check out the docs for detailed info on which date parsing character does what.

这篇关于如何在Angular中将日期转换为可读形式,并同时连接两个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆