1. i tried `new Date("2018-05-21T01:31:16+0000")`...
# suitescript
n
1. i tried
new Date("2018-05-21T01:31:16+0000")
but didn't work out. error =
RangeError: Date is invalid.
2. tried
format.parse
and
type=date/datetime
and got a string as return
s
new Date() not working for you ?
n
yes,
new Date()
works but with parameters of the string doesn't
r
What I did for my script was split the string using 'T' then '-'. Then I passed it to the Date constructor.
new Date(date_parts[0], date_parts[1] - 1, date_parts[2]);
But mine has the same format for all the date, not sure about yours
n
@rustyshackles Thank you. That's a good idea since the date format is fixed in this case
Will stop struggling with
N/format
any more.
c
Would also recommend momentjs and see if that’ll parse it out correctly. That’s the only library I use with dates these days.
n
@creece tried to
new Date()
then set y,m,d but still got errors. momentjs is the final solution...
@creece but weirdly....again....
"2018-09-04T03:05:02.000Z"
turned to be
3 Sep 2018
using
moment(dateStr).toDate()
. drive me crazy