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

shane
New Contributor II

That will give you a date-time string but not a timestamp. Try to create a timestamp from that and that is my issue.

if you want to adjust a GMT timestamp to PST (-7), what about:
Date.now().getTime() + (3600 * -7)
or
Date.parse(Date.now().plusHours(-7)).getTime()

shane
New Contributor II

Unfortunately that isn’t how timezones work though.
I would have to calculate the offset based on the America/Las_Angeles timezone at the given DateTime.

Specific example, I need to generate the timestamp for the following date to pass into an API: “2019-09-21 00:00:00” but I need to write a bunch of logic to determine whether that time in the America\Las_Angeles timezone would be PDT or PST (as daylight savings time may or may not be in effect, which effects the offset). This should be simple if I could create the Date object in a timezone other than UTC but I can’t find a way to do so.

The API I haver to hit is set to PST in it’s handling of the passed in timestamp. It only returns data from the provided timestamp until end of that day. If I pass in a UTC based timestamp then the results will be way off, and I am needing a full day of data which means passing in a PST based timestamp for the 00:00:00 time of a given date (which I can’t generate in SnapLogic).

Supratim
Contributor III

@shane
Put Date.parse() over there.

shane
New Contributor II

as was gone over above, this doesn’t work