简体   繁体   English

JavaScript Vuex或Date错误

[英]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. 但它始终显示02.06之类的内容。 Everything from past month instead of current Date. 过去一个月的所有内容,而不是当前日期。

Here is my part where I pass Timestamp to getter 这是我将时间戳传递给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 这是我的getter函数,应该处理这个原始时间戳记

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 我的时间戳格式来自HTML输入type =“ date”,看起来像这样2018-07-17T10:10

I hope someone knows the solution 我希望有人知道解决方案

I'Ve found the solution through a tip from RobG > 我通过RobG的提示找到了解决方案>

Note that new Date('2018-07-17T10:10') is (incorrectly) treated as UTC by Safari. 请注意,新的Date('2018-07-17T10:10')被Safari(错误地)视为UTC。 >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 – RobG 2小时前,我将我的Date类替换为moment.js,并更改了我传递给moment.js类的时间戳格式。

Thank you @RobG 谢谢@RobG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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