I'm working with Bootastrap-Vue in bination with JavaScript and I want to use the Moment.js in my code.
I get the time but it's not correct...Can some one please help me??
By the way, this is my first question at StackOverflow, so I apologize if I'm ask it wrong.
Thank you.
var moment = require('moment')
export default {
name: 'something',
data() {
return {
something: [],
currentPage: 1,
total_something: 1,
something_fields: {
id: {
label: 'Id',
sortable: true
},
purpose: {
label: 'Purpose',
sortable: false
},
state: {
label: 'State',
sortable: false
},
updated: {
key: 'updated',
label: 'Updated',
formatter: (value, key, item) => {
return moment(item.updated).calendar();
}
}
},
}
},
created() {
this.loadSomething(0, 10)
},
watch: {
currentPage: function (newPage) {
this.loadSomething(newPage, 10)
}
}, methods: {
loadSomethings(currentPage, limit) {
if (!(Number.isInteger(currentPage) && Number.isInteger(limit))) {
currentPage = 0
limit = 10
}
var offset = (currentPage - 1) * limit
window.API.get('something?offset=' + offset + '&limit=' + limit)
.then(response => {
this.something = response.data.something;
this.total_something s = response.data.total;
console.log(response.data.something)
})
.catch(e => {
this.errors.push(e)
})
}
}
}
I'm working with Bootastrap-Vue in bination with JavaScript and I want to use the Moment.js in my code.
I get the time but it's not correct...Can some one please help me??
By the way, this is my first question at StackOverflow, so I apologize if I'm ask it wrong.
Thank you.
var moment = require('moment')
export default {
name: 'something',
data() {
return {
something: [],
currentPage: 1,
total_something: 1,
something_fields: {
id: {
label: 'Id',
sortable: true
},
purpose: {
label: 'Purpose',
sortable: false
},
state: {
label: 'State',
sortable: false
},
updated: {
key: 'updated',
label: 'Updated',
formatter: (value, key, item) => {
return moment(item.updated).calendar();
}
}
},
}
},
created() {
this.loadSomething(0, 10)
},
watch: {
currentPage: function (newPage) {
this.loadSomething(newPage, 10)
}
}, methods: {
loadSomethings(currentPage, limit) {
if (!(Number.isInteger(currentPage) && Number.isInteger(limit))) {
currentPage = 0
limit = 10
}
var offset = (currentPage - 1) * limit
window.API.get('something?offset=' + offset + '&limit=' + limit)
.then(response => {
this.something = response.data.something;
this.total_something s = response.data.total;
console.log(response.data.something)
})
.catch(e => {
this.errors.push(e)
})
}
}
}
Share
Improve this question
asked Jan 24, 2018 at 7:20
omizomiz
9491 gold badge8 silver badges11 bronze badges
3
-
2
I get the time but it's not correct
is not very helpful. – connexo Commented Jan 24, 2018 at 7:22 -
moment(item.updated).calendar();
-> What isitem.updated
? Why are you using calendar ? What is the current output versus the expected output ? What is the result ofconsole.log(moment().format("DD/MM/YYYY HH:mm")
? – Weedoze Commented Jan 24, 2018 at 7:26 - Dear Weedoze, like I said, this is my first time and I'm also junior programmer. The reason I use calendar is to print like for example(Last Thursday at 3:32 PM) or (Today at 9:00 AM). console.log(moment().format("DD/MM/YYYY HH:mm") has not results in my code. – omiz Commented Jan 24, 2018 at 8:08
2 Answers
Reset to default 1formatter: (value, key, item) => {
if(item.updated) {
return moment(item.updated).format(); // format(YOUR DATE FORMAT)
}
}
https://momentjs./docs/
use this :
updated:{
key: 'updated',
label: 'Updated',
formatter: (value, key, item) => {
return moment(item.updated).format('DD-MM-YYYY');
}
}