0

I am converting current date into British Summer Time (BST)

let date = new Date()
this.datePipe.transform(date, 'MMMM d, yyyy', 'BST');

It will return my current pc time after using datepipe transform also.

  • `BST` isn't a valid ISO 639-2 format so it wont work. More details [here](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) and [here](https://angular.io/guide/i18n-common-locale-id). As far as I've red it seems that the only difference between that timezone and the English one is that `BST`is 1 hour "behind". Maybe you could just format it as English format and substract 1 hour. – Jacopo Sciampi May 23 '22 at 13:28

2 Answers2

0

I ran into that some time ago, you need to import the correct locale data.

Only the en-US locale data comes with Angular. To localize dates in another language, you must import the corresponding locale data. See the I18n guide for more information.

further details can be found in the Angular documentation on DatePipe, Angular documentation on Internationalisation and in depth discussions in another StackOverflow question (scroll down in the answers!)

Charlie V
  • 980
  • 1
  • 6
  • 12
0

As mentioned in comments under your question, BST is not a valid timezone offset.

Internally, date pipe relies on the browser's handling of Date.parse (docs). All browsers should accept the standardized format containing time offset, e.g. 01 Jan 1970 00:00:00 GMT or 01 Jan 1970 00:00:00 GMT-02:00.

Some browsers will accept non-standard values, like the most common timezone abbreviations (e.g. PST, MST) for backward compatibility. Apparently BST is not one of those.

If you're willing to risk possible compatibility issues, you could try using relevant TZ database name in brackets instead of timezone offset, e.g. 01 Jan 1970 00:00:00 (Europe/London). This works on Chrome, and might work for other browsers, but again it's environment dependent as it's not part of the standard, so you would have to make sure it works on all platforms you support and can expect it to change over time.

TotallyNewb
  • 3,884
  • 1
  • 11
  • 16