How to Get Current Date and Time in AngularJS?
In this example, we will learn how to get current date time in angular js application. we can get current date and time with specific format like yyyy-mm-dd, dd/mm/yyyy, mm-dd-yyyy hh:mm:ss etc. we will display current date and time using angular js ng-bind directive.
You can see bellow example we use Date object for getting current date and time. So you can see bellow syntax, example, full example and also output bellow. let's see it and i hope it will help you.
Syntax:
{{ 'Date Object' | date: 'Date Format' }}
Example:
{{ CurrentDate | date: 'dd/MM/yyyy' }}
index.html:
<!doctype html>
<html>
<head>
<title>How to get Current Date and Time in AngularJS? - ItSolutionStuff.com</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body ng-app='myapp'>
<div ng-controller="myCtrl">
<p>{{ CurrentDate | date:'dd/MM/yyyy'}}</p>
<p>{{ CurrentDate | date:'MM/dd/yyyy'}}</p>
<p>{{ CurrentDate | date:'dd/MM/yyyy HH:mm:ss'}}</p>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myapp', []);
app.controller('myCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.CurrentDate = new Date();
}]);
</script>
</html>
Output:
02/07/2019
07/02/2019
02/07/2019 09:23:47
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- AngularJS Filter Change Date Format in Controller Example
- AngularJS Remove Duplicates Object from Array Example
- AngularJS Drag and Drop Table Rows Example with Demo
- PHP AngularJS Populate Dynamic Dropdown Example
- AngularJS Ajax Autocomplete Using Typeahead in PHP Example
- How to Copy to Clipboard without Flash in AngularJS?
- AngularJS Convert Comma Separated String to Array Example
- How to Call AngularJS Controller Function in JQuery?
- How to Remove # from URL in AngularJS?
- How to Hide Div After Some Time in AngularJS?
- AngularJS Sorting(using Orderby Filter) Table Data Example
- How to Change Date Format using Date Filter in AngularJS?
- AngularJS - How to Limit String Length using Filter?
- AngularJS - How to Capitalize the First Letter of Word Example
- How to Remove HTML Tags from String in AngularJS?