Hello all. I'm getting a Unix Timestamp from an A...
# suitescript
d
Hello all. I'm getting a Unix Timestamp from an API that I need to set the
trandate
of a timebill with in NetSuite. All sorts of things come into play (server timezone, user pref timezone, etc). Any guidance on how to get this right. Its for a SuiteApp, is I need to ensure the solution is universal
My thought is to leverage suiteQL in some way to convert the timestamp into a date object.
I'm thinking if I using the
Copy code
runtime.getCurrentUser();
This would help me identify if I should use the system timezone or the users timezone.
currently, I'm setting the
trandate
to new Date(
unix_timestmap
* 1000)
e
You might take a look at the momentjs library. We use it in our SuiteScripts for some more complex conversions like this. https://momentjs.com/
💯 1
The unix timestamp is UTC. But, it sounds like you are wanting to convert that to the user’s local timezone.
b
use the Date constructor to convert the timestamp into Date in the server's timezone (which will be pacific)
👍 1
then use format.format to make a date time string the string will be in the current's users date time format, so you discard the time and use Record.setText
👍 1
s
I tend to try and standardize on UTC if possible (and a unix timestamp should be UTC) .. then translate that to whatever timezone representations are useful as needed.