在angularjs中更改日期时间格式 [英] Change the date time format in angularjs

查看:151
本文介绍了在angularjs中更改日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从api获取日期和时间.我想更改日期和时间格式.

I'm getting date and time from the api. I want to change the date and time format.

我越来越喜欢这个"2016-05-12","07:17:35".

I'm getting like this "2016-05-12","07:17:35".

更改格式,例如2016年5月12日晚上7:30:

Change the format like 12-may-2016 7:30 PM:

<table class="table">
    <thead>
        <tr>
            <th>Time</th>
            <th>Place</th>
        </tr>
    </thead>
    <tbody ng-repeat="l in dataget">
        <tr>                    
            <td>{{l['time']}}</td>
            <td>{{l['place']}}</td>                             
        </tr>
    </tbody>
</table>

推荐答案

* controller.js

  var myApp = angular.module('myApp', []);
  myApp.filter('datetime', function($filter)
  {
    return function(input)
     {
      if(input == null){ return ""; } 
      var _date = $filter('date')(new Date(input),
                          'MMM dd yyyy - HH:mm:ss'); 
     return _date.toUpperCase();
 };
});

在HTML中

<div ng-app="sampleapp">
<table class="table">
<thead>
    <tr>
        <th>Time</th>
        <th>Place</th>
    </tr>
</thead>
<tbody ng-repeat="l in dataget">
    <tr>                    
        <td>{{l['time'] | datetime}}</td>
        <td>{{l['place']}}</td>                             
    </tr>
</tbody>

这篇关于在angularjs中更改日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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