suggest you use Moment.js, just import moment to your vue component
Sep 10, 2018
8
Level 12
Displaying time from database query in Vue without the seconds.
I pass data from an eloquent query to Vue using props. I want then to display the time data in this collection as 00:00 instead of 00:00:00.
I have tried moment.js with no luck.
How can I do this.
The data is stored in item.start and item.finish in the vue instance.
<template>
<div>
<div v-for="item in todays_hours">
<div class="row">
<div class="col-2">
<div hidden="" ></div>
</div>
<div class="col-2" >
<div v-text="{{ item.start }}"></div>
</div>
<div class="col-2" >
<div>{{ item.finish }}</div>
</div>
<div class="col-2" >
<div v-text="item.job_number"></div>
</div>
<div class="col-2" >
<div v-text="(item.climbing)?'Yes':'No'"></div>
</div>
<div class="col-2" >
<button @click="onEdit" class="btn-warning btn-sm mb-1">Edit</button>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'DisplayHoursComponent',
props: ['dayCheck', 'hoursWorked'],
data() {
return {
hours_list: this.hoursWorked,
todays_hours: []
}
},
mounted() {
for (var i = 0; i < this.hours_list.length; i++) {
if (this.hours_list[i].day === this.dayCheck) {
this.todays_hours.push(this.hours_list[i])
}
}
Event.$on('onAddedEntry', (data) => {
if(data.day === this.dayCheck){
this.todays_hours.push(data);
}
})
},
methods: {
onEdit()
{
}
}
}
</script>
<style scoped>
Level 67
Just use a real date when using moment. Since you're only working with the time portion, the actual date is irrelevant.
let time = '12:31:51';
let formatted = moment("2018-03-01 " + time).format('hh:mm');
console.log(formatted); // 12:31
1 like
Please or to participate in this conversation.