jk121960
jk121960

Reputation: 873

SuiteScript 2.0 Apply Time Zone to field

I need to "GET" a date field from a "Record" and apply a timezone, in 1.0 it was just using the getDateTimeValue and passing the timezone as the second parameter. In 2.0 you only have the generic getValue and when passing the TZ as the second value or passing it in the options package, it seems to just ignore it. Anyone have an idea? I can't find it in the docs.

thanks in advance

Upvotes: 0

Views: 2915

Answers (1)

Krypton
Krypton

Reputation: 5276

In SuiteScript 2.0 you need to use the N/format module to apply the timezone to the raw date.

An example of usage is as follows:

require(['N/format'], function () {

    var format = require('N/format');
    var now = new Date();
    console.log(now);
    var nyTime = format.format({
        value:now,
        type:format.Type.DATETIME,
        timezone:format.Timezone.AMERICA_NEWYORK
    });
    console.log('NY time is ' + nyTime);
    var gmt = format.format({
        value:now,
        type:format.Type.DATETIME,
        timezone:format.Timezone.GMT
    });

console.log('London time is ' + gmt);
});

You can paste the above into the console of a new transaction page and run it to demonstrate how it's used.

Upvotes: 2

Related Questions