如何使用moment.js转换参数日期

时间:2018-08-05 22:37:17

标签: javascript vuejs2 momentjs

我有一个值this.birthday,其中包含该值Mon Aug 06 2018 00:00:00 GMT-0500 (CDT)T00:00:00-00:00

即使我的日期选择器配置为如此,我的生日模型也会收到该值...

<el-date-picker v-model="birthday" v-validate="'required|date_format:YYYY-MM-DD'" type="date" placeholder="yyyy-mm-dd" data-date-format="yyyy-MM-dd" :picker-options="pickerOptions1"></el-date-picker>

如何使用 moment.js 将此日期值转换为YYYY-MM-DD

我正在尝试将生日中保存的日期值调整为所需的输出...。但是我不知道如何操作。这些文档似乎都没有帮助。

onSubmitted() {
  axios.post(`${process.env.KITTY_URL}/api/v1/cats/`, {
    name: this.name,
    age: this.age,
    gender: this.gender,
    cat_type: this.cat_type,
    litter_mates: this.litter_mates,
    weight: this.weight,
    birthday: moment(this.birthday.toString()).format('DD-MM-YYYY'),<---?????? what should this be???
    weight_unit: this.weight_unit
  })
    .then(response => {
      console.log(response);
      response.status === 201 ? this.showSuccess = true : this.showDanger = true
    })
    .catch(error => {
      console.log(error);
      this.showDanger = true;
    })
}

2 个答案:

答案 0 :(得分:0)

由于const express = require('express'); const app = express(); const port = process.env.PORT || 5000; const googlePlayApp = require('google-play-scraper'); const appToScrape = 'com.mojang.minecraftpe'; app.get('/gPlay', (req, res) => { console.log('==================== /gPlay ===================='); const gPlayResults = googlePlayApp.app({appId: appToScrape}); gPlayResults.then(function(result) { res.send({ appObject: result }) }); }); app.listen(port, () => console.log(`Listening on port: ${port}`)); 已将el-date-picker对象设置为Date。要将其转换为格式化的字符串,只需使用以下命令,它就可以工作。

birthday

答案 1 :(得分:0)

好吧,这是我发现的。...看着互联网,我发现了这个随机页面。...https://github.com/ankurk91/vue-bootstrap-datetimepicker

这是一个线索。

// ...
options: {
  format: 'DD/MM/YYYY',
  useCurrent: false,
}

这似乎是关键。我的birthday参数现在收到正确的格式。