6

I am using Date() to get the current time in local time zone. And I have formatted that as follows:

this.today = new Date();
      from = new DatePipe('en-Us').transform(this.today, 'dd:MM:yyyy hh-mm-ss');

Now I want to convert the from date time to Europe/London time zone. How Can I do this without moment. Please help me

Anil
  • 1,748
  • 8
  • 32
  • 67

1 Answers1

8

I solved my issue by adding an another parameter for timezone according to https://angular.io/api/common/DatePipe

Here is the update code:

to = new DatePipe('en-Us').transform(this.today, 'dd:MM:yyyy hh-mm-ss', 'GMT+1');
Patricio Vargas
  • 5,236
  • 11
  • 49
  • 100
Anil
  • 1,748
  • 8
  • 32
  • 67
  • 1
    Yes, that is the answer, – Anil Sep 21 '18 at 17:56
  • I don't think this supports `Europe/London` or something similar. Is there a way to avoid providing the offset? – Suyog Feb 05 '21 at 06:18
  • Caveat: If you give the input date as a string but without a timezone portion, the string will be parsed under the assumption of belonging to the timezone given as third parameter. – Björn Jul 27 '21 at 08:57
  • @Anil sir can you tell me how to pass America/Los_Angeles in above function? – Kapil Soni Nov 23 '21 at 13:04
  • I'm thinking we could use an static dictionary with whatever key you want and then the offset as a value. { pst: -0700 } // vegas – TheZerg Apr 22 '22 at 18:38