[英]how to convert paramater date with moment.js
I have a value this.birthday
which containes this value Mon Aug 06 2018 00:00:00 GMT-0500 (CDT)T00:00:00-00:00
我有一个值this.birthday
包含此值Mon Aug 06 2018 00:00:00 GMT-0500 (CDT)T00:00:00-00:00
my birthday model receives this value even tho' my datepicker is configured like so... 即使我的日期选择器配置如下,我的生日模型也会收到此值...
<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>
How can I use moment.js to convert this date value to YYYY-MM-DD
? 如何使用moment.js将此日期值转换为YYYY-MM-DD
?
I'm trying to manipulate the date value held inside birthday to my desired output....but I have no clue how. 我试图将生日中保存的日期值调整为所需的输出...。但是我不知道如何。 None of the documentation seems to be helping. 这些文档似乎都没有帮助。
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;
})
}
Since the el-date-picker
is already setting a Date
object to birthday
. 由于el-date-picker
已将Date
对象设置为birthday
。 To convert it to a formatted string, just use the following and it should work. 要将其转换为格式化的字符串,只需使用以下命令,它就可以工作。
moment(this.birthday).format('YYYY-MM-DD')
Ok here is what I found....looking into the internet I found this random page.... https://github.com/ankurk91/vue-bootstrap-datetimepicker 好的,这就是我所发现的...。。。看着互联网,我发现了这个随机页面。... https://github.com/ankurk91/vue-bootstrap-datetimepicker
within it was a clue.. 里面有个线索。
// ...
options: {
format: 'DD/MM/YYYY',
useCurrent: false,
}
this seemed to be the key. 这似乎是关键。 my birthday
param now receives the correct format. 我的birthday
参数现在收到正确的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.