Angularjs get current date time


Angularjs get current date time: You can get current date time in angularjs on Html template and javascript both. Here we have explained both the Html template date time and javascript date time with syntax and example.


Angularjs get current date time

You can get current date time in angularjs as :

Get current date time on Html template in AngularJs :

You can get current date time on html template as below :

Angularjs get current date time Syntax

{{ date_expression | date : format : timezone}}

Example:

Current date time on html Example

Current Date : {{CurrentDate | date:'dd/MM/yyyy'}}
24 Hrs Current Date Time : {{CurrentDate | date:'HH:mm:ss'}}
12 Hrs Current Date Time : {{CurrentDate | date:'hh:mm:ss a'}}

Which will give current date time

Get Current Date time in Angular Controller Js

You can get current date time in angularjs as :

Angularjs get current date time on js Syntax

 <script type="text/javascript">
 angular.module('myApp', ['ionic'])
.controller('MyCtr', function($scope, $filter) {
            var date = new Date();
            $scope.date-format-ddMMyyyy = $filter('date')(new Date(), 'dd/MM/yyyy');
            $scope.date-format-ddMMMMyyyy = $filter('date')(new Date(), 'dd, MMMM yyyy');
            $scope.date-format-HHmmss = $filter('date')(new Date(), 'HH:mm:ss');
            $scope.date-format-hhmmsstt = $filter('date')(new Date(), 'hh:mm:ss a');
        });
</script>

<div ng-app="myApp" ng-controller="MyCtr">
        dd/MM/yyyy format - <div ng-bind = "date-format-ddMMyyy"></div>
        dd, MMMM yyyy format - <div ng-bind = "date-format-ddMMMMyyyy"></div>
        24 Hour time- <div ng-bind = "date-format-HHmmss"></div>
        12 Hour time- <div ng-bind = "date-format-hhmmsstt"></div>
</div>
Note : For date format reference you can go through –Date Format Reference .

Advertisements

Add Comment

📖 Read More