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.

2
  • Can you explain better your needs? What output do you want? Commented Jul 10, 2015 at 10:02
  • 1
    He wants +05:30 instead of +0530. But 'Z': 4 digit (+sign) representation of the timezone offset (-1200-+1200) is what is in the documentation so I dont think you can. Commented Jul 10, 2015 at 10:16

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.