I am trying to get the current local time instead ...
# suitescript
m
I am trying to get the current local time instead of the server time which
new Date()
returns. I found this answer here, I followed it, but noticed that the code at the end is a little bit weird, here it is:
Copy code
var timeRecord = record.load({
  id: 1,
  type: 'customrecord_currenttime'
});

var timezone = config.load({type: config.Type.USER_PREFERENCES}).getValue({fieldId:"TIMEZONE"})

var currentTime = timeRecord.getValue('custrecord_currenttime_now');

var usersTime = format.format({
    value: usersTime,
    type: format.Type.DATETIME,
    timezone: format.Timezone.timezone
});
As you can see,
usersTime
is passed to
.format
which is weird. Also, shouldn't currentTime be the local time?
b
Date objects use server time
usually Pacific Time
netsuite records/searches that get or set text use the current user's datetime settings
m
So why the answer mentions timezons?
b
you can use N/format to convert between a Date object and a datetime string in the current user's format
suiteanswer code is garbage most of the time
format.Timezone.timezone
is undefined
m
lol
got it, thanks ❤️
b
look at format.Timezone if you want timezome options
m
ok
b
on the more practical side, I've never used N/format to do anything but format to and from the current user's datetime
m
Most of the time, I get confused by N/format too, always trying to avoid it.