sandeep
sandeep

Reputation: 3345

Convert UTC timestamp to PST in Angular

In my application, I am getting a finish timestamp data from server side which is in this format - 2021-02-19T06:30:58 . This is in UTC.

The requirement from client is to convert this timestamp in PST hours. The format should look like Feb 19, 2021 06:30 AM (Time should be converted to PST hours) . How to do this in Angular/Typescript.

For now this is how I am doing in my html code - {{ (finishTimeStamp | date : 'MMM d, yyyy')}} and it gives the result as Feb 19, 2021.

How can I include the time as well after converting it to PST hours.

Upvotes: 3

Views: 1527

Answers (2)

Dhanush
Dhanush

Reputation: 53

You can add time manually using getTime(). which gets time in milliseconds.

  1. 1 minute = 60000 milliseconds
  2. 60 minutes = 60x60000
  3. 5 hours = 300x60000
  4. and so on...

Eg:

curDate=new Date();

futDate=new Date(this.curDate.getTime()+330*60000);

This will add 5 hours 30 minutes to current time.

Upvotes: 2

Pranav Kasetti
Pranav Kasetti

Reputation: 9915

Maybe try this:

{{ (finishTimeStamp | date : 'MMM d, yyyy hh:mm a' : '-0800') }}

Upvotes: 4

Related Questions