Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS : tomorrow's date and yesterday's date with some ng component

Tags:

date

angularjs

$scope.date = new Date();   
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

I have written something like this, and I know its not correct. Please correct me to display it in this format {{date | date:'EEE, dd MMM yyyy'}}

Edit 1: I want the tomorrow's date to be displayed on click of right arrow button and yesterday on left arrow button click at same position where Wed, Sept 3, 2014. Hide/show feature, how to code, I don't understand how to get it using angular. Reference image https://www.google.co.in/search?q=full+calendar+day+view&source=lnms&tbm=isch&sa=X&ei=PIqjVbP4FIijugS3qYOgBg&ved=0CAcQ_AUoAQ&biw=1360&bih=595#imgrc=2E7vtXzvWMYS0M%3A

like image 504
Vinit Desai Avatar asked Jul 13 '15 08:07

Vinit Desai


People also ask

How to create currentdate object in angular component?

Date object can be created in Angular component as seen below currentDate: Date = new Date(); // This creates an date object with current date date1: Date = new Date('01.01.2020'); // This creats an date object with given day month and year Let' declare angular component

How to change the datetime format in angular?

To change the datetime format in angular we have to pass date time format parameter to the angular pipe as shown below. { { date_value | date :'short'}} // 6/15/19, 5:24 PM. The format ‘short’ is one of the predefined date formats in angular which converts our date value to ’M/d/yy, h:mm a’ format.

What is fulldate in AngularJS?

AngularJS date filter is used to convert a date into a specified format. When the date format is not specified, the default date format is ‘MMM d, yyyy’. Parameter Values: The date filter contains format and timezone parameters which is optional. “fullDate” – equivalent to “EEEE, MMMM d, y” (Tuesday, May 7, 2019)

How to compare date with current date in angular?

Angular compare Date with current Date. Below is angular example to compare given date is before or after of an current date. We can use <,> !==,<=,>= relational operators for comparing dates


1 Answers

Probably you want something like this?

JSFiddle

HTML:

<div ng-app="myApp" ng-controller="myCtrl">
    <p><a href="" ng-click="showToday = true; showTomorrow = false">Left arrow</a></p>
    <p><a href="" ng-click="showTomorrow = true; showToday = false">Right arrow</a></p>
    <span ng-show="showToday">Today: {{date | date:'EEE, dd MMM yyyy'}}</span>
    <span ng-show="showTomorrow">Tomorrow: {{tomorrow | date:'EEE, dd MMM yyyy'}}</span>
</div>

JS:

angular.module('myApp', [])
.controller('myCtrl', function ($scope) {
    $scope.showToday = false;
    $scope.showTomorrow = false;
    $scope.date = new Date();   
    $scope.tomorrow = new Date();
    $scope.tomorrow.setDate($scope.tomorrow.getDate() + 1);
});
like image 151
michelem Avatar answered Oct 14 '22 00:10

michelem