When in a 2.1 userevent script I create a new Date...
# ask-stanley-ai
a
When in a 2.1 userevent script I create a new Date() object and set it as the value of a Date/Time field, it resolves to 6 hours earlier than the actual current time. What's the simplest way to fix that?
c
AI generated answer (using internal Slack threads):
The issue you're experiencing is due to the fact that NetSuite's server time is set to Pacific Time (PT). When you create a new Date() object in JavaScript, it uses the local time of the server, which is PT. If you're in a different timezone, this can cause the time to be off when you set it as the value of a Date/Time field. To fix this, you can adjust the time to your local timezone by adding or subtracting the timezone offset from the Date object. Here's an example of how you can do this:
Copy code
javascript
var serverTime = new Date();
var timezoneOffset = serverTime.getTimezoneOffset() * 60000; // getTimezoneOffset() returns the offset in minutes, so we convert it to milliseconds
var localTime = new Date(serverTime.getTime() + timezoneOffset);
In this code,
serverTime
is the current time in PT,
timezoneOffset
is the difference between PT and your local timezone in milliseconds, and
localTime
is the adjusted time in your local timezone. You can then use
localTime
as the value for your Date/Time field. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.828009546
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827787519
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825971603
Please provide your feedback on this answer.