AngularJs Get Previous Day

AngularJs Get Previous, Day Next, Day Month, Year, Month, Time

How to get Previous Day, Next Day, Month, Year Month Time using AngularJs?

Hello everyone, I am going to share the code-sample for Get  the Previous Day, Next Day, Month, Year, Month Time etc.


The Table of content as given below

1.       The AngularJs code sample
2.       The HTML code sample
3.       The Full Live demo code
4.       The OutPut link

The AngularJs code sample

        var app = angular.module('dayApp', []);

        app.controller('dayCtrl', function ($scope) {
            $scope.today = new Date();
            $scope.preday = new Date().getDate() - 1;
            $scope.nextday = new Date().getDate() + 1;
            $scope.premonth = new Date().getMonth() - 1;
            $scope.nextmonth = new Date().getMonth() + 1;
            $scope.curentyear = new Date().getFullYear();
        });

The HTML code sample

<div ng-app="dayApp">
    <h4>Angularjs Get Previous Day, next Day, Month, Year Month Time </h4>
    <div ng-controller="dayCtrl">
        <p class="col">Current Date: {{today | date :'dd-MM-yyyy'}}</p>
        <p class="col"> Previous Day: {{preday}}</p>
        <p class="col"> Next Day: {{nextday }}</p>
        <p class="col"> Previous Month: {{premonth }}</p>
        <p class="col"> Next Month:{{nextmonth}}</p>
        <p class="col"> Current Year :{{curentyear }}</p>
    </div>
</div>

The Full Live demo code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Angularjs Get Previous Day, next Day, Month, Year Month Time</title>
    <link rel="stylesheet" href="style.css" />
    <script src="https://code.angularjs.org/1.4.1/angular.js"></script>
    <script>
        var app = angular.module('dayApp', [])
        app.controller('dayCtrl', function ($scope) {
            $scope.today = new Date();
            $scope.preday = new Date().getDate() - 1;
            $scope.nextday = new Date().getDate() + 1;
            $scope.premonth = new Date().getMonth() - 1;
            $scope.nextmonth = new Date().getMonth() + 1;
            $scope.curentyear = new Date().getFullYear();
        });
    </script>
</head>

<body ng-app="dayApp">
    <h4>Angularjs Get Previous Day, next Day, Month, Year Month Time </h4>
    <div ng-controller="dayCtrl">
        <p class="col">Current Date: {{today | date :'dd-MM-yyyy'}}</p>
        <p class="col"> Previous Day: {{preday}}</p>
        <p class="col"> Next Day: {{nextday }}</p>
        <p class="col"> Previous Month: {{premonth }}</p>
        <p class="col"> Next Month:{{nextmonth}}</p>
        <p class="col"> Current Year :{{curentyear }}</p>
    </div>
</body>

</html>


The Output: go to link http://embed.plnkr.co/to7wqz/preview


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^