-1

I have a datetime value in "YYYY-MM-DD HH:mm:ss" format e.g. "2017-04-03 05:00:07". I don't want to change the value but need to display the value as "MMM DD, YYYY" format e.g. "Apr 03, 2017".

Is there anyway to display the value in different format using html?

Geeky Ninja
  • 5,765
  • 8
  • 35
  • 50
sudarsan
  • 75
  • 2
  • 14

3 Answers3

0

Simple way to achieve your requirement is by using Moment.js

var TodayDate = moment().format('MMM DD, YYYY');
var selectedDate = moment('2017-04-03 05:00:07').format('MMM DD, YYYY');
console.log("today = "+TodayDate);
console.log("selected = "+selectedDate);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
SjVnyk
  • 468
  • 1
  • 6
  • 21
0

refer the angular filter in the below link.

use this 'MMM' format in default date filter available in the angular js to obtain the month and use the formats in the required order

{{1288323623006 | date:'MMM-dd-yyyy'}} try this

https://docs.angularjs.org/api/ng/filter/date

0

Create directive as below and use in HTML:

Directive:

var app = angular.module("MyApp", []);

var datefrmt = "yyyy-MM-dd";

app.directive('dateFormateModel', function (dateFilter) {
    return {
        require: 'ngModel',
        link:function (scope, elm, attrs, ctrl) {            
            var dateFormat = datefrmt;           
            ctrl.$formatters.unshift(function (modelValue) {
                return dateFilter(modelValue, dateFormat);
            });
        }
    };
});

HTML:

<div class="propertyValue"><input type="text" ng-model="gc.tempApplicationSettingModel.CreatedDate" date-formate-model class="form-control"  /></div>