-> Netsuite uses PDT timezone for time functions(new Date(),Moment.js etc) in Server side.
-> In client scripts it uses the time zone of the User (Browser side)
-> In saved search loaded in script it generally shows the time based on the (Company preferences)
Related posts
https://blog.prolecto.com/2015/01/30/netsuite-server-side-timezone-settings/
The same issue has been faced during one of the development. The issue was the following:
When we try to create a new date object for the date field value, then the date is added with +7:00 hours to the date value.
The issue was due to the javascript data object is in the pacific format. This adds the extra 7 hours to the date object.
The following are the solution/code snippet for getting the correct date object:
var date = new Date(Date.UTC(2021, 5, 12, 0, 0, 0))
console.log(date.toISOString());
Issue Faced : I created 2 restlet scripts one for bulk update APIs(#1) and one for fetch APIs(#2) for a same record. I could see a discepency in the date time a difference of 5 hours between date in update(#1) and date fetched in API(#2). Input was in UTC format. In update API it was correct from UI.
Root cause problem : In search in restlet script dates are showed based on the company Preference. In Updating record we use new date() function which works in PDT,
Solution
Normally companies does not change their time zone in company wide preferences. So you can hard code in this case
in other case
We can also use N/config module to load company preferences. You can find the time offset and format accordingly.
This will also can be used as a solution for date/Date time Format.
//Using Format module – recommended – Day light saving is applied
//Using Format module – recommended – Day light saving is applied
let dateTimeToUtc = (dateVal) => {
if (dateVal) {
// To fix to Netsuite Time(CST) to UTC
return format.parse({
value: dateVal,
type: format.Type.DATETIME
}).toISOString();
} else {
return ”
}
}
// Using moment – least recommended – (Day light saving is not applied)
let dateTimeToUtc = (dateVal) => {
if (dateVal) {
// To fix to Netsuite Time(CST) to UTC
let targetDateFormat = ‘MM/DD/YYYY hh:mm:ss a’ //Company preference format
let dateInCentralTime = moment(dateVal, targetDateFormat);
return dateInCentralTime.add(5, ‘hours’).format(“YYYY-MM-DDTHH:mm:ss.SSSS”)+ ‘Z’ //(5 is for caliberating hour differences)
} else {
return ”
}
}
let dateToUtc = (dateVal) => {
return dateVal ? format.parse({
value: dateVal,
type: format.Type.DATE
}).toISOString() : ”
}
let dateToUtc = (dateVal) => {
let targetDateFormat = ‘MM/DD/YYYY’
return dateVal ? moment(dateVal, targetDateFormat).format(“YYYY-MM-DDTHH:mm:ss.SSSS”) + ‘Z’ : ”
}
Above are the suggested solution for fixing