I used angular moment js on my angular app. I want to show date and time according to the time zone of the current user. I'm unable to apply time zone globally on my app.
https://github.com/urish/angular-moment
I tried this.
angular.module('myapp').constant('angularMomentConfig', {
timezone: 'Europe/London' // e.g. 'Europe/London'
});
In one of my view -
{{home.eventStart| amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a'}}
In one of my controller -
$scope.profile.eventStart = moment(data.start).format('YYYY-MM-DD hh:mm a');
I'm not getting any changes in both cases, even after I set the time zone. Am I missing something ?
You cannot change constant after you set it. As injections are not dependent on module.constant or module value, this should do the trick:
angular.module('myapp').value('angularMomentConfig', {
timezone: 'Europe/London' // e.g. 'Europe/London'
});
The timezone parameter is optional. If you omit it, it will use the time zone of the local machine automatically. That is the default behavior of moment.js and of the JavaScript Date object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With