How to format date in angularjs



  • 5 Answer(s)

    Actually , one good thing is angular js consists itself built-in date filter.

    Compile the example code here.

     

    // in your controller:
    $scope.date = '20140313T00:00:00';
     
    // in your view, date property, filtered with date filter and format 'MM/dd/yyyy'
    <p ng-bind="date | date:'MM/dd/yyyy'"></p>
     
    // produces
    03/13/2014
    

    The variety of date formats in date-filter are here.

    Supported format strings which is used to get the correct format in the date picker .

    Answered on December 17, 2018.
    Add Comment

    This code should works fine,

    {{1288323623006 | date:'medium'}}: Oct 29, 2010 9:10:23 AM
    {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: 2010-10-29 09:10:23 +0530
    {{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}: 10/29/2010 @ 9:10AM
    {{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}: 10/29/2010 at 9:10AM
    
    Answered on December 17, 2018.
    Add Comment

    We can achieve this using by the given simple code,

    {{ oD.OrderDate.replace('/Date(','').replace(')/','') | date:"MM/dd/yyyy" }}
    
    Answered on December 17, 2018.
    Add Comment
    <input ui-date ui-date-format="mm/dd/yyyy" ng-model="valueofdate" /> 
    
    <input type="date" ng-model="valueofdate" />
    Answered on February 22, 2019.
    Add Comment
     {{dateUTCField  +'Z' | date : 'mm/dd/yyyy'}}
    
     e.g. dateUTCField = '2018-01-09T10:02:32.273' then it display like 01/09/2018
    Answered on November 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.