I have the following JSON string that I would like to extract the date and the time from:
{ "id": 1, "time": { "date": "2019-06-12 11:51:22.000000", "timezone_type": 3, "timezone": "UTC" }, "productCategory": "some cat", "kitchen": { "house": { "id": 555, "name": "bigHouse" }, "id": 55, "name": "smallKitchen", "country": "US" } }
I do it currently like this:
<tr v-for="(cabinet, i) in cabinets">
<td>{{ cabinet.kitchen.id }}</td>
<td>{{ cabinet.productCategory }}</td>
<td>{{ getDate(cabinet.time.date) }}</td>
<td>{{ getTime(cabinet.time.date) }}</td>
</tr>
<script>
const axios = require('axios');
export default {
name: "Cabinets",
data() {
return {
bedroom : this.$session.get('bedroom').id,
cabinets: []
}
},
mounted() {
axios({
method: 'GET',
url: `/bedroom/${this.bedroom}/cabinets`
})
.then(response => {
this.cabinets = response.data
})
},
methods: {
getDate(datetime) {
return new Date(datetime).toISOString().slice(0,10);
},
getTime(datetime) {
return new Date(datetime).toISOString().slice(11,19);
}
}
}
</script>
The date works fine but the time doesn't. The date and time are retunred as follows respectivly: 2019-06-12
and 09:51:22
. The time should have been 11:51:22
. This is probably becasue I'm using the method Date()
when trying to get the time but when I tried using Time()
it gave an error:
[Vue warn]: Error in render: "ReferenceError: Time is not defined".
I, however, even if I could find a really simple fix for the time, really don't like this way with slicing and was searching for methods that does do this for me, because as you can see, slicing the string is malfunctioning already.