How to get Current Date and Time in AngularJS?

  • 05-04-2022
  • 1205
  • Angular JS
  • Haresh Chauhan

In this example, I will you show how to get the current date and time in the angular js we will learn how to make this and how to use the angular application with a specific date format. you can use date format like yyyy-mm-dd, dd/mm/yyyy, mm-dd-yyyy hh:mm:ss and many more formats you can use as per your need. Now we will make this example using angular js ng-bind directive.

So, now you can follow bellow simple we are getting time and date from the date object in this example. So, You can see the example and make it.

Syntax:

{{ 'Date Object' | date: 'Date Format' }}

{{ CurrentDate | date: 'dd/MM/yyyy' }}

Example : index.html


<!doctype html>
<html>
<head>
    <title>How to get Current Date and Time in AngularJS? - webappfix.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="AppCtrl">
        <p>{{ CurrentDate | date:'MM/dd/yyyy'}}</p>
        <p>{{ CurrentDate | date:'dd/MM/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('AppCtrl', ['$scope', '$http', function($scope, $http) {
        $scope.CurrentDate = new Date();
        console.log($scope.CurrentDate);
    }]);
</script>
</html>

I hope you like this article.

Thanks...


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :