[英]VueJS - array with Edm.DateTime Elements, transform dates and show them in table
Got following .json: 得到以下.json:
[{
"DATE": "/Date(1511346375000)/",
"POSID": "1"
},
{
"DATE": "/Date(1511346375000)/",
"POSID": "2"
}
}]
I'm loading the unique values in my table via v-for: 我通过v-for在表中加载唯一值:
<tr v-for="(value, key) in countDates">
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
Thing is, I want to display the readable Date like: 2017-11-23 事情是,我想显示可读的日期,如:2017-11-23
So I have to remove the "/" and convert it in a UTC-Formatted-Date. 因此,我必须删除“ /”并将其转换为UTC格式的日期。
Can I achieve that via computed properties? 我可以通过计算属性来实现吗? Or is there another possibility?
还是还有另一种可能性?
convertDate1 (value) {
if (value === 'null') {
return value.replace('null', 'no date specified')
} else {
var d = new Date(parseInt(value.replace('/Date(', '').replace(')/', ''), 10))
}
var month = d.getUTCMonth() + 1 // months from 1-12
var day = d.getUTCDate()
var year = d.getUTCFullYear()
return year + '/' + month + '/' + day
}
+ +
<td>{{ convertDate1(value.key) }}</td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.