Kamoulox
Kamoulox

Reputation: 351

How to format a date with formatDate on angular

I try to get this format with angular formatDate

"2019-01-01T00:00:00Z"

So I use this code

formatDate(
  '2019-01-01',
  'yyyy-MM-ddT00:00:00Z',
  'en-US'
)

The result is 2019-01-01T00:00:00+0200

Z is replaced by the zone. There is a valid way to make the format I need ?

Upvotes: 0

Views: 256

Answers (1)

sabithpocker
sabithpocker

Reputation: 15566

You have to escape Z as a string or it will be treated as per this

"yyyy-MM-ddT00:00:00\'Z\'"

formatDate(
  '2019-01-01',
  "yyyy-MM-ddT00:00:00\'Z\'",
  'en-US'
)

Upvotes: 2

Related Questions