Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Angularjs Get Current Date or Time or DateTime with Example

Apr 23, 2015
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.


To get current datetime using AngularJS we need to write the code like as shown below


<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.cdate = new Date();
});
</script>

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

Current Date Time: {{cdate1 | date:'dd/MM/yyyy hh:mm:ss a'}}
Current Date :{{cdate1 | date:'dd/MM/yyyy'}}
Current Time :{{cdate1 | date:'hh:mm:ss a'}}

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Phani said...

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

Suresh Dasari said...

Thanks Phani i updated the code please check it once....

Anonymous said...

Cant we show the timezone also?

Anonymous said...

Its not working

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.