Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date & Time with Timezone display using Angularjs

How to display the Timezone information along with Date & Time using Angularjs:

I am trying to display Date and Time using the binding defined below:

{{data.filterData.run_date|date:'h:mm a'}} on {{data.filterData.run_date|date:'M/d/yy'}}

Something like above showing IST for India, CST for US and correct timezones for every end user and conversion.


UPDATE


I am getting the data in below format and in UTC format but is auto-converted by browser by clients machine: 2015-10-26T08:46:05+0000

How can we show the abbreviated Timezone as per above format or converted date and time & not specifically in UTC? As i have different clients and end users; so this should be dynamic to end user.

Thanks in advance!

like image 792
GOK Avatar asked Nov 09 '15 10:11

GOK


2 Answers

But in versions 1.3.x only supported timezone is UTC,You can use external js if working with 1.3.x like Moment js

{{ user Defined date| date: 'MMM d, y H:mm:ss' : 'UTC' }}

Since version 1.4.0-rc.0 AngularJS supports other timezones too.

In HTML Template Binding

{{ date_expression | date : format : timezone}}

In JavaScript

$filter('date')(date, format, timezone)

More...

like image 131
Dark Army Avatar answered Oct 21 '22 14:10

Dark Army


use the following code:

<html>
<head>
<title>Localization App</title>

</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript">
    var app=angular.module('myApp',[]);
    app.controller('myCtrl',function($scope)
    {
        $scope.CurrentDate = new Date();    
    });
</script>
<div ng-app="myApp" ng-controller="myCtrl">
     Date : {{CurrentDate | date:'dd/MM/yyyy'}}  </br>
     Date_1 : {{CurrentDate | date:'dd, MMMM yyyy'}}  </br>
     Time : {{CurrentDate | date: 'hh:mm:ss a'}} </br> 
     Time_1 : {{CurrentDate | date: 'HH:mm:ss Z'}} </br> 
</div>

</body>
</html>

Output:

Date : 13/12/2017
Date_1 : 13, December 2017
Time : 10:33:42 AM
Time_1 : 10:33:42 +0530

like image 41
Anand Avatar answered Oct 21 '22 14:10

Anand