This topic contains 7 replies, has 0 voices, and was last updated by MChammaTX 7 years, 1 month ago.

  • Author
    Posts
  • #18261

    MChammaTX

    var localDate = format.format({value:new Date(), type: format.Type.DATETIMETZ, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date “,localDate) -> 10/1/2017 8:57:29 pm

    so far so good the right date string is displayed

    let’s convert it to a date object as per suiteanswer https://netsuite.custhelp.com/app/an…ail/a_id/61223

    var localDateObj = format.parse({value:localDate, type: format.Type.DATETIME, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) -> 2017-10-02T01:57:29.000Z

    ok didnt work lets try

    var localDateObj = format.parse({value:localDate, type: format.Type.DATETIMETZ, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) -> 2017-10-02T01:57:29.000Z

    nope

    Ok back to native JavaScript conversions since this has been pretty inconsistent for awhile…
    This is a cached copy. Click here to see the original post.

  • #18262

    Veda

    hi,

    localDate value passed to parse function is taken as Mountain Time (-7 GMT) and hence the behaviour.

    thanks,

    Veda.

  • #18263

    MChammaTX

    I’m pretty sure I tried passing just a date object using new Date() and also passing a date string with no time i.e. 10/1/2017.

    Are you saying the API is just doing arithmetic and not passing the actual timezone time?

    I will try it again later with just new Date and report back.

  • #18264

    MChammaTX

    var localDateObj = format.parse({value:new Date(), type: format.Type.DATETIMETZ, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) – > 2017-10-03T00:18:33.569Z

    still not Central

    var localDateObj = format.parse({value:new Date(), type: format.Type.DATETIME, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) – > 2017-10-03T00:18:33.569Z

    still not Central

    var localDateObj = format.format({value:new Date(), type: format.Type.DATETIMETZ, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) – > 10/2/2017 7:20:15 pm

    central but as a string I need it as an object

    var localDateObj= format.format({value:new Date(), type: format.Type.DATETIME, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj);- > 10/2/2017 7:20:15 pm

    central but as a string I need it as an object

    var localDateStr= format.format({value:new Date(), type: format.Type.DATETIMETZ, timezone: format.Timezone.AMERICA_CHICAGO})

    log.debug(“new date 2”,localDateObj) – > 10/2/2017 7:20:15 pm

    var localDateObj = new Date(localDateStr) – > 2017-10-03T02:22:24.000Z

    No matter what combination I try I can’t get a date object in local time.

  • #18265

    Veda

    Getting a date object in Local time for a server side script would be a challenge.

    if its a client script, date object would be in local time, but if its a server script, then timezone would be PST only. Pls see: https://netsuite.custhelp.com/app/an…ail/a_id/37356

    thanks,

    Veda.

    Netsuite Consultant

    Skalable Technologies.

  • #18266

    MChammaTX

    Thanks Veda.

    What’s really funny is that when I try

    var dt = new Date();

    log.debug(“new date 1”,dt);

    It shows in Pacific which is what I would expect

    But if I run it again it shows in GMT all of a sudden

    var dt = new Date();

    log.debug(“new date 1”,dt);

    I was starting to think that maybe this is something happening in the log function to output the date object and not the date object itself so I tried

    var dt = new Date();

    log.debug(“new date 1”,dt.getTime());

    And crazy enough it shows the corresponding time for CST Chicago???

    This is a mess. I’m starting to get the feeling that this is a practical joke by the NetSuite SuiteScript team.

    I’ve spent 2 hours just trying to get some consistency with date times. This is happening in the map function of my map reduce. I’m going to try moving it to getInput and maybe run some code in the debugger to see if it is just an issue with the MR function or the log function.

  • #18267

    pcutler

    Have you considered running a search and using formula fields with SESSIONTIMEZONE to get the session time zone and DBTIMEZONE to get the database time zone? The difference in the TZ_OFFSETs between the two is the amount of time to add/subtract from the new date object.

  • #18268

    MChammaTX

    Thanks pcutler that seems like a promising workaround

You must be logged in to reply to this topic.