I could to the trick with the function below, but ...
# suitescript
g
I could to the trick with the function below, but I'm still wondering if there is a better way to do it..
Copy code
function fnStringToDate(dateString) {
        // e.g. dateString = "2020-03-30T12:00:00Z"
        var day = dateString.substring(8, 10)
        var month = dateString.substring(5, 7) - 1
        var year = dateString.substring(0, 4)

        var date = new Date()

        date.setDate(day)
        date.setMonth(month)
        date.setFullYear(year)

        return date
    }
e
I use
moment.js
whenever I'm working with dates, and parsing a JSON date is just:
Copy code
moment(date, moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
g
Thank you very much @erictgrubaugh For that you just upload the moment.js to the File Cabinet and code something like what is written below? define(["./moment.js"]), function (moment){}
e
yep
I'm sure there are native JS solutions, but I use
moment
so often that I don't mind pulling it in even for single lines
g
Awesome, I think it makes more sense than building my own local function at least hahah Besides moment, which other packages do you often use in NetSuite?
e
lodash
I use those two in just about every project/client
s
I use both of those as well. Notably I think moment naturally takes in the ISO format your string is using. Another date library I like is https://date-fns.org/
g
Awesome! Thanks for sharing @erictgrubaugh @stalbert! Have a nice day 😉
e
I was having trouble getting
moment
to recognize the format by default when I implemented that code; could be different now
s
weird- I've been getting 'deprecation' warnings if I use any format other than that ISO8601
d
this is great to know - does Netsuite support date time offsets?