cancel
Showing results for 
Search instead for 
Did you mean: 

Can't create a non-UTC Date object to call .getTime() on

shane
New Contributor II

I need to pull data from an API that needs a timestamp as a parameter. This API retrieves data from a system (not in my control) that is based in the America/Las_Angeles timezone. I have tried for hours to find a way to generate a non-UTC Date object (LocalDateTime object doesn’t contain a getTime() method) so that I can call .getTime() but I seem to only be able to get a string value of the converted UTC Date into my desired timezone.

I tried to find a way to use the getTimezoneOffset() function, but I need a non-UTC Date object in order to get the valid offset from so I’m back to square one.

Can anyone provide an example of creating a Date object in Snap with a non-UTC timezone that I can call getTime()? (I just need to generate a timestamp based on a PST Date with a 00:00:00 time)

I tried creating the converted string (which I can’t get to include the timezone, because even though the docs point to SimpleDateFormat (Java Platform SE 7 ) as a reference I cannot get the value output for any of the time zone components) and appending ’ PST’ but it still created a UTC Date.

I have spent way too long trying to do something so simple that is a couple lines of code in almost any language and needs some guidance lol.

15 REPLIES 15

gsuresh92
New Contributor

Date.parse(Date.now().toLocaleDateString({“timeZone”:“America/Los_Angeles”, “format”: “yyyy-MM-dd’T’00:00:00Z”})).getTime() ?