0
{{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.

Tushar
  • 85,780
  • 21
  • 159
  • 179
Danish Khan
  • 143
  • 1
  • 9

2 Answers2

0

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

potatopeelings
  • 40,709
  • 7
  • 95
  • 119
0

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.

Community
  • 1
  • 1
ricksmt
  • 888
  • 2
  • 13
  • 34