使用VueJS转换Javascript中的日期格式 [英] Convert date format in Javascript using VueJS
本文介绍了使用VueJS转换Javascript中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的日期格式为19 Oct 2017
,并且想要将其转换为这种格式20171019
I have a date format of 19 Oct 2017
and want to convert it to this format 20171019
有快速的方法吗?我在VueJs中使用FlatPickr
.如果有帮助,请在下面找到我的代码.
Is there a quick way of doing this? I am using FlatPickr
in VueJs. Please find my code below if its any help.
import flatPickr from 'vue-flatpickr-component';
import 'flatpickr/dist/flatpickr.css';
import Navigation from './Navigation'
import bus from '../bus'
export default {
data() {
return {
showPanel: false,
isClosed: false,
arrival: null,
departure: null,
config: {
dateFormat: "Ymd"
}
}
},
components: {
flatPickr
},
methods: {
closeMenu: function() {
this.$store.state.showBooking = false;
}
},
mounted() {
bus.$on('show-booking', () => {
this.showPanel = true;
})
}
}
推荐答案
您可以轻松地做到这一点:
You can do this easily:
import moment from 'moment'
methods: {
format_date(value){
if (value) {
return moment(String(value)).format('YYYYMMDD')
}
},
},
然后:
format_date(date)
这篇关于使用VueJS转换Javascript中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文