In Typescript I need to convert a localdate (UMT) to PST. I’ve tried .setZone but this did not work, says “Property ‘setZone’ does not exist on type ‘LocalDate’.”. CoPilot mentioned 'toLocaleString(). but I cannot figure out how to make this work. Any help is appreciated!!
LocalDate as a type is not timezone-rich - it only represents a calendar date. The timezone-rich type that you want to go for is TimeStamp which is by default always stored in UTC format and can be freely interchanged between timezones. The only thing to be wary of is that if you’re parsing a string into a timestamp, make sure you parse it in the accurate timezone that the string represents for the timestamp to be accurate.
If you can provide some more context around what you need this for, it would be easier to provide direct solutions
Thank you. For a form backed by typescript, I need the end user to type in a date/localdate (say 4/17/2025), of type LocalDate, it will be UTC. I have to convert to timestamp (say 4/17/2025 00:00:00) , convert it to PST (so 4/16/2025 18:00:00), then set it back to Localdate. (4/16/2025).
Going down this route, can’t figure it out though:
myDate: Timestamp,
let newDate= myDate.toInstant().atZone('America/Los_Angeles').toLocalDate()....error Property 'toInstant' does not exist on type 'Timestamp'.typescript(2339)