0

I'm getting a date from a service but it seems this is not really a date format.

I tried to print like:

{{vm.NapIncident.RecordDate | date: 'HH:mm:ss dd-MM-yyyy'}}

But it's printing

2018-10-11+01:00 on the frontend.

Is there a way to show the record date in the format that I want?

3
  • I tried your code (date format) and it displays as what you want. There must be something else that is causing the issue in your environment. Maybe caching? Try kb.iu.edu/d/ahic Commented Oct 11, 2018 at 7:41
  • 2
    What is vm.NapIncident.RecordDate? String? Date object? Can you create working snippet (icon [<>] in editor) to demonstrate your issue? Are you using angular (like in title) or angularjs (like in tag)? Commented Oct 11, 2018 at 7:45
  • I assume that vm.NapIncident.RecordDate is a string. How can I do this if that is a string? Filtering doesn't work Commented Oct 11, 2018 at 8:11

3 Answers 3

1

try moment.js

moment().format("h:mm:ss a,Do MMMM YYYY,");
Sign up to request clarification or add additional context in comments.

Comments

1

Please Use moment js. For more advance level you can make filter for dateformat and use code as below.

(function () {
'use strict';

angular.module('app.filter')
    .filter('utcDate', utcDate);

function utcDate() {
    return function (value, format) {
        moment.locale("en");
        switch (format) {
            case 'shortTime':
                format = 'LT';
                break;
            case 'shortDate':
                format = 'L';
                break;
            case 'communityDate':
                format = 'LT L';
                break;
            case 'orderDate':
                format = 'LT ll';
                break;
            case 'orderLongTime':
                format = 'HH:mm';
                break;
            case 'activityDate':
                format = 'L LT';
                break;
            case 'chatComivo':
                format = 'MMM D';
                break;
            case 'broadcastReplyTime':
                format = 'HH:mm a';
                break;
            case 'broadcastReplyDate':
                format = 'MM/DD/YYYY';
                break;
            case 'promotionDate':
                format = 'MM/DD/YYYY';
                break;
            case 'converstionDate':
                format = 'MMMM DD YYYY, h:mm:ss a';
                break;
            case 'lastRead':
                format = 'lll';
                break;
             case 'test':
                format = 'HH:mm:ss dd-MM-yyyy';

        }

        //var localDate = moment.utc(value).local(); this is for to convert date into utc date
        //return localDate.format(format);return moment().format(format); 

return    moment().format(format)     }    }})();

And use following html

this date <p>{{date | utcDate:'test'}}</p>

you can update it as per your requirement.

Comments

0

If you are receiving the date in this format "dd/mm/yyyy". You can use regex to convert the date.

 this.NapIncident.recordDate = new Date(this.NapIncident.recordDate.replace(/(\d{2})- 
(\d{2})-(\d{4})/, "$2/$1/$3"))
 }

Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.