AngularJS過濾器filter-時間日期格式-渲染日期格式-$filter

來源:互聯網
上載者:User

標籤:目前時間   擷取   src   html模板   image   span   自訂   頁面   short   

  

  今天遇到了這些問題索性就 寫篇文章吧

  話不多說直接上栗子 

 

   不管任何是HTML格式還是JS格式必須要在  controller 裡面寫

  

  

  // new Date() 擷取目前時間  
  yyyy-MM-ddd //是返回的格式 下面會一 一列出 這種返回格式
$scope.wwwwwww = $filter(new Date(),‘yyyy-MM-dd‘)

//或者這樣寫
//這樣是 指定date類型 可以省略不寫 下面的是多此一舉 但是我感覺有人會鑽牛角尖所以嘛 嘿嘿
$scope.wwwwwww = $filter(‘date‘)(new Date(),‘yyyy-MM-dd‘) 

 

   在HTML模板裡這樣寫 

  

 

   頁面上就會得到時間

  

  

 

 

  下面說在HTML裡面寫

 

  

 

   在HTML模板裡面 

  date 是固定套路

  yyyy-MM-dd HH:mm 下面會說

  

 

   頁面上的時間

  

   下面講解返回的日期格式 

  斜體紅字的就是上面的日期講解

    自訂日期格式化:
        年月日:({{ nativeDate | date:‘yyyy-MM-dd‘ }})2017-01-06
        時分秒:({{ nativeDate | date:‘HH:mm:ss.sss‘ }})21:22:09.990
    
    年份格式化:
    四位年份:({{ nativeDate | date:‘yyyy‘ }})2017
    兩位年份:({{ nativeDate | date:‘yy‘ }})17
    一位年份:({{ nativeDate | date:‘y‘ }})2017

    
    月份格式化:
        英文月份:({{ nativeDate | date:‘MMMM‘ }})April
        英文月份簡寫:({{ nativeDate | date:‘MMM‘ }})Apr
        兩位元字月份:({{ nativeDate | date:‘MM‘ }})04
        一年中的第幾個月份:({{ nativeDate | date:‘M‘ }})4

    日期格式化:
        數字日期:({{ nativeDate | date:‘dd‘ }})06
        一個月中的第幾天:({{ nativeDate | date:‘d‘ }})6
        英文星期:({{ nativeDate | date:‘EEEE‘ }})Thursday
        英文星期簡寫:({{ nativeDate | date:‘EEE‘ }})Thu

    小時格式化:
        24小時制數字小時:({{ nativeDate | date:‘HH‘ }})18
        一天中的第幾個小時:({{ nativeDate | date:‘H‘ }})21
        12小時制數字小時:({{ nativeDate | date:‘hh‘ }})04
        上午或下午的第幾個小時:({{ nativeDate | date:‘h‘ }})9

    分鐘格式化:
        數字分鐘數:({{ nativeDate | date:‘mm‘ }})26
        一個小時中的第幾分鐘:({{ nativeDate | date:‘m‘ }})40

    秒數格式化:
        數字秒數:({{ nativeDate | date:‘ss‘ }})08
        一分鐘中內的第幾秒:({{ nativeDate | date:‘s‘ }})8
        毫秒數:({{ nativeDate | date:‘sss‘ }})990

    本地日期格式化
    ({{ nativeDate | date:‘medium‘ }})Apr 14, 2017 4:40:08 PM
    ({{ nativeDate | date:‘short‘ }})4/14/16 4:40 PM
    ({{ nativeDate | date:‘fullDate‘ }})Thursday, April 14, 2017
    ({{ nativeDate | date:‘longDate‘ }})April 14, 2017
    ({{ nativeDate | date:‘mediumDate‘ }})Apr 14, 2017
    ({{ nativeDate | date:‘shortDate‘ }})4/14/17
    ({{ nativeDate | date:‘mediumTime‘ }})4:40:08 PM
    ({{ nativeDate | date:‘shortTime‘ }})4:40 PM

 

 

  

  以上就是AngularJS 過濾器返回日期的講解  有不對的地方望大神指點一二

 

 

  

 

 

  

AngularJS過濾器filter-時間日期格式-渲染日期格式-$filter

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.