Is there a consistent way that I can retrieve a UT...
# suitescript
d
Is there a consistent way that I can retrieve a UTC timestamp from NetSuite regardless of the timezone set in Company and/or User Prefs?
c
If you have a date object, use Date.UTC()
d
I'm using new Date().valueOf(). (which is equivalent no?)
c
are you using native dates or moment
d
native
Full transparency .. I'm making use of an API call out that wants a timestamp
and we're getting different values based on different users (so, clearly a preference thing).
c
appears to be pretty much the same thing
d
I'd like to come up with a getUTCTimeStamp function that works for all preference combinations
c
is this server-side or client side? I have a function client side that always returns the date in the current user's timezone. May need to format it first then convert it
d
server-side
c
function getTodayInCurrentUserTimezone() { return format.parse({type: format.Type.DATE, value: format.format({type: format.Type.DATETIME, value: new Date()})});
Copy code
}
dunno if the server-side is throwing it off.
d
Ya, likely
Odd ... I thought new Date().valueOf() wouldn't care about timezone (maybe I need to do more testing)
c
well if serverside is not in the same location and you only use new Date, then it could def be off
maybe someone has a better answer for you though. I would try formatting just as a test
d
I would have thought that if
new Date().valueOf()
was run on any server with any system timezone would produce the same integer value. It's simply
the number of milliseconds since 1 January 1970 UTC
. So wouldn't the number be that same any where in teh world?
c
If the server is on the west coast and you're on the east coast, then potential 3 hours difference in that UTC time because the date is different. Unless i'm just wrong.
d
I'll hunt down 2 differently located NetSuite instances and report back here
b
Date.now is what I usually use
that represents the time now, which is actually the same regardless of the timezone
1000000 2