'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.
Solution 1:[1]
Maybe try this:
{{ (finishTimeStamp | date : 'MMM d, yyyy hh:mm a' : '-0800') }}
Solution 2:[2]
You can add time manually using getTime(). which gets time in milliseconds.
- 1 minute = 60000 milliseconds
- 60 minutes = 60x60000
- 5 hours = 300x60000
- 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dhanush |
