简体   繁体   中英

JavaScript Vuex or Date bugs

I have a problem with the Date Class. It should take a parameter (wheres a timestamp in) and output the right day of month and the month. But it always shows something like 02.06. Everything from past month instead of current Date.

Here is my part where I pass Timestamp to getter

<workCard v-if="services_getSort(sortServicesBy).length > 0" v-for="i in services_getSort(sortServicesBy).data" :key="i.source">
  <div slot="content" class="d-flex justify-content-between ">
    <router-link :to="'/services/' + i">
      <div style="min-width:4.0rem" class="pr-1 align-items-center">
        <span style="color:black;"><i class="fas fa-calendar-alt fa-md"></i> {{outputDateOnly(i.start)}}</span>
        <br>
        <span style="color:darkblue"><i class="fas fa-clock fa-md"></i> {{outputTimeOnly(i.start)}}</span>
      </div>
    </router-link>
    <div class="p-1 d-flex mt-2">
      <span style="color:black">></span>
    </div>
    <div style="min-width:4.0rem" class="align-items-center">
      <span v-if="i.end != ''">
                                <span style="color:black;"><i class="fas fa-calendar-alt fa-md"></i> {{outputDateOnly(i.end)}}</span>
      <br>
      <span style="color:darkblue"><i class="fas fa-clock fa-md"></i> {{outputTimeOnly(i.end)}}</span>
      </span>
      <i v-if="i.end == ''" class="fas mt-3 fa-infinity fa-md"></i>
    </div>

And here is my getter function which should handle this raw timestamp

export const outputDateOnly = (state, getters) => {
  return payload => {
    let check = getters.zeroCheck;
    let date = new Date(payload)
    console.log(payload);

    console.log(`${date.getDay()}.${date.getMonth()}`);

    return `${date.getDay().toString()}.${date.getMonth().toString()}`
  }
}

My Timestamp Format comes from HTML input type="date" and looks like this 2018-07-17T10:10

I hope someone knows the solution

I'Ve found the solution through a tip from RobG >

Note that new Date('2018-07-17T10:10') is (incorrectly) treated as UTC by Safari. >Don't use the built-in parser. – RobG 2 hours ago I replaced my Date Class with moment.js and changed my Timestamp format which i pass to moment.js class

Thank you @RobG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM