Introduction:
Here I will explain how to get current datetime in AngularJS or get only current date or time from AngularJS. By using “new Date()” function we can get current date or time or datetime in AngularJS.
Description:
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to get current datetime or date or time using AngularJS.
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to get current datetime or date or time using AngularJS.
|
If you want to check it in complete example you need to
write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Current Date Time
in Angularjs</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.cdate = new Date();
});
</script>
</head>
<body data-ng-app="sampleapp"
data-ng-controller="samplecontrol">
<form id="form1">
<div>
Current Date Time:<b> {{cdate |
date:'dd/MM/yyyy hh:mm:ss a'}}</b><br />
Current Date :<b>{{cdate |
date:'dd/MM/yyyy'}}</b><br />
Current Time :<b>{{cdate |
date:'hh:mm:ss a'}}</b>
</div>
</form>
</body>
</html>
|
Live
Demo
For
live demo check below time date and time values
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
if possible please write the piece of code in another manner as this is executing and not showing the value that is assign from the model
like
{{cdate | date:'dd/MM/yyyy hh:mm:ss a'}} is not appearing and showing like 24/04/2015 11:43:47 AM
Thanks Phani i updated the code please check it once....
Cant we show the timezone also?
Its not working
Note: Only a member of this blog may post a comment.