0

I need to save a date formatted in this way "2015-03-25T12:00:00Z" and also show the date in the format dd-MM-yyyy or MM-dd-yyyy depending where the user it is. Another issue I have I would like to show a text "expired" instead of a date when a date is expired. However, I'm showing the date code I have hoping for a solution.

 $scope.getItemScheduledTitle = function(item) {

        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!
        var yyyy = today.getFullYear();

        if(dd<10) {
            dd='0'+dd
        } 

        if(mm<10) {
            mm='0'+mm
        } 

        today = mm+'/'+dd+'/'+yyyy;

        var title = "";
        if (item.from && item.to == null)
            title += "from " + item.from + " to " + " ... ";
        if (item.to && item.from == null)
            title += "from " + today + " to " + item.to;
        if (banner.to && banner.from)
            title += "from " + banner.from + " to " + banner.to;
        if (item.expired === true)
            title +=  "Expired";
        return title;
    }

this the view of it:

<i class="icon--big fa fa-clock-o cursor-pointer" aria-hidden="true" title="{{ getBannerScheduledTitle(banner) }}" ng-class="{'expiredRed' : banner.expired}">
Jakub
  • 2,367
  • 6
  • 31
  • 82
  • You should take a look at momentjs for date formatting – ukn May 29 '17 at 15:10
  • 1
    Unfortunately I cannot use extra plugins I need a different solution thanks – Jakub May 29 '17 at 15:16
  • 1
    angular has **[date filter](https://docs.angularjs.org/api/ng/filter/date)** for the display part. As for saving...whenever you pass a date object as data in `$http` it will be converted to format shown automatically. Try running `new Date().toJSON()` in your console – charlietfl May 29 '17 at 15:18
  • https://stackoverflow.com/q/20131553 maybe this is your solution – Oswald May 29 '17 at 15:38
  • @Oswald—it's much better to use the title as a link rather than just pasting a link, e.g. [*AngularJS - convert dates in controller*](https://stackoverflow.com/questions/20131553/angularjs-convert-dates-in-controller). ;-) – RobG May 29 '17 at 22:27
  • This does not work with the new app:) – Oswald May 30 '17 at 09:07

0 Answers0