0

I'm using the DHTMLX Scheduler in my web app and want to get the data for each event and found a way to do it with scheduler._events which returns this:

1581498064943: {…}
​​
_eday: 2    ​​
_end_date: undefined    ​​
_first_chunk: true    ​​
_last_chunk: true    ​​
_length: 1    ​​
_sday: 1    ​​
_sorder: 0   ​​
_sweek: 0    ​​
_timed: true    ​​
end_date: Date Tue Jan 02 2018 00:05:00 GMT+0100 (Central European Standard Time)    ​​
event_length: ""    ​​
event_pid: ""    ​​
id: 1581498064943    ​​
rec_pattern: ""
​​rec_type: ""    ​​
start_date: Date Tue Jan 02 2018 00:00:00 GMT+0100 (Central European Standard Time) ​​
text: "New event"

the problem is when I convert it into a string to store it as a JSON later, JavaScript converts dates into iso 8601 and loses a day in the conversion:

"1581498064943": {
        "start_date": "2018-01-01T23:00:00.000Z",
        "end_date": "2018-01-01T23:05:00.000Z",
        "text": "New event",
        "id": 1581498064943,
        "_timed": true,
        "_sday": 1,
        "_eday": 2,
        "_length": 1,
        "_sweek": 0,
        "_sorder": 0,
        "_first_chunk": true,
        "_last_chunk": true,
        "event_pid": "",
        "event_length": "",
        "rec_pattern": "",
        "rec_type": ""

2018-01-02 becomes 2018-01-01

1
  • Because letter "Z" in ISO-8601 means Coordinated Universal Time (UTC) and it is GMT+0000. It's the same time, in other time-zone. Commented Feb 12, 2020 at 9:49

2 Answers 2

1

It's not reducing oneday. It's because of your timeZone. check the following code.

var x= new Date("Date Tue Jan 02 2018 00:05:00 GMT+0100 (Central European Standard Time)")

x.toISOString()

y = new Date(x)

You will get the initial date again. So, to use it from the JSON again you need that ISOstring to be converted again

Sign up to request clarification or add additional context in comments.

Comments

0

Better try with Unix epoch seconds format to resolve this issue.

const now = Date.now(); // Unix timestamp in milliseconds
console.log( now );

Once you convert this you can retrieve the same exact time based on your local region specification.

var utcSeconds = 1581501372817/1000;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
console.log(d);

1 Comment

thank you ! i'll use that it is more relevant in my case ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.