1

I am currently using vue-date-pick@1.4.1 as date picker. The problem is after the user select a date and when the form is submitted, the date changed to be one day difference. I console.log the payload of the payload object before post to the endpoint. This is the value of the payload object for the date.

BirthDate: Tue Jul 06 2010 00:00:00 GMT+0800 (Malaysia Time)

I troubleshoot this by stringify this payload object. After I stringify this payload object, the value becomes

"BirthDate":"2010-07-05T16:00:00.000Z"

This is because my date is set to UTC date? If so, how do I set it to local date?

This is the code.

DatePick.eform--input_datepicker(v-model="BirthDate", :format="'DD/MM/YYYY'")

This is the method which generate the payload.

generatePayload() {
  let _obj = { };

  Object.keys(eFormModel).forEach(key => {
    let value = this.$store.state.eform[key];

    _obj[key] = value;
  });

  // TODO: Remove later
  //----------------------------
  console.log(_obj);
  const jsondata = JSON.stringify(_obj);
  console.log(jsondata);
  //----------------------------

  return _obj;
},

and the model

export let model = {
  BirthDate: { value: null, format: 'dateTime', updateRetrieve: formatDate, updateSend: toDate },   
}
Steve
  • 2,963
  • 15
  • 61
  • 133
  • 1
    Does this answer your question? [How to JSON stringify a javascript Date and preserve timezone](https://stackoverflow.com/questions/31096130/how-to-json-stringify-a-javascript-date-and-preserve-timezone) – slauth Jul 30 '21 at 14:07
  • Just one question, so is my object date in UTC format? How do I know? – Steve Jul 30 '21 at 14:28
  • 2
    There is no internal "format" for date objects, it is just a local timestamp (1278345600 in your case) with an associated timezone (GMT+0800 (Malaysia Time) in your case)… – slauth Jul 30 '21 at 14:39

0 Answers0