{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: 2010-10-29 09:10:23 +0530
I want to time zone with colon like +05:30 in angularjs.
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: 2010-10-29 09:10:23 +0530
I want to time zone with colon like +05:30 in angularjs.
You could do the below
{{ d = (1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z').split(''); d.splice(-2, 0, ':'); d.join('') }}
but a better (and cleaner) way would be to write your own custom filter.
Note - by the way, angular expressions do not support regular expression literals (in case you are thinking of simplifying it that way) - https://docs.angularjs.org/guide/expression
I referenced this Q&A, when I developed this answer:
myApp.config(['$provide', function($provide) {
$provide.decorator('dateFilter', ['$delegate', function($delegate) {
return function() {
var args = arguments;
// Replace my 'ZZ' option with a 'Z' I can find
args[1] = args[1].replace('ZZ', '!!Z!!');
// Get the original, Angular output
original = $delegate.apply(this, args);
// Find my marked time zones, clean up, and add the colon
return original.replace(/!!([-|+]?)(\d\d)(\d\d)!!/, '$1$2:$3');
};
}])
}]);
You can see a JSFiddle of it here. This approach opts to extend the built-in date filter with a ZZ
option for a timezone with a colon. The only thing this doesn't account for is escaped letters, but that's not a problem on my project with this extension. You may need to check for that, especially if you override the original Z
option.