if i have a date in JSON stringified fashion from ...
# suitescript
e
if i have a date in JSON stringified fashion from a client script (Eastern Time Zone) feeding into a Suitelet, and the Suitelet is running in a different time zone (Pacific), dates will be backdated by 1 day. There has to be an elegant solution to this. Anyone? Sample: Client fed value of
2021-11-02T04:00:00.000Z
(JSON stringified) Suitelet processes, converts string to date (
new Date(2021-11-02T04:00:00.000Z)
), end up with
Mon Nov 01 2021 21:00:00 GMT-0700 (PDT)
date object. I can parse 2021-11-02 from the original JSON stringified string and create a string
11/02/2021
and create a new Date from there, but is there any more elegant approach?
b
If you are using the Date with one of record apis to set a value, then you can probably just use the Date as is
but if your string is 2021-11-02T040000.000Z, then that date really is 11-01 in pacific time, so it is accurate
e
here the client is reading in the date into a string (with other info in there), where it is then stringified and passed to a Suitelet… so I don’t have a Date object
b
you used the Date constructor to change your iso-8601 string into a date
e
The Date input on screen is really “11/2/2021” (as it is not a datetime input, rather date); the client renders that as 0400… because I am in the Eastern timezone. So, technically, I only want the short date…
b
the date is correct, the string given represents Mon Nov 01 2021 210000 GMT-0700 (PDT)
e
Except it is incorrect bec it should have been the short date, really - see my previous response (crossed paths)
b
if you want, you can set the hours to a more agreeable number before you change it into a string
or you can just send the string 11/2/2021 instead of 2021-11-02T040000.000Z
e
yes, so basically, capture it in the Client script - I was trying to avoid that. Also, that’s clunky - though we know where the data center is, i guess so i can fudge it by 3 hours
or the short string, correcty
thanks, @battk - I guess this is the only way
b
for suitelets you can usually just use the text you get from the field directly when setting fields on records
the date/time/timezone formats match between field values in suitelets clientside and serverside
e
Correct - if you submit the Suitelet. In this case, the Client script was preparing a string (for some reason - beyond this scope) for processing. Thanks!