当后台传来的集合中包含日期时,显示的是一串数字。此时我们需要过滤器将这串数字转换成正常的年月日格式。
首先前台页面接收到该日期:

<template>
	<view class="content" v-if="hasLogin">
		<view class="newsDetail" v-for="(item,index) in discussionList" :key="index">
			<view class="newsTime">{{item.dCreateTime | dCreateTime}}</view>
		</view>
	</view>
</template>

使用过滤器:

export default {
		filters: {  
			dCreateTime(value) {
				console.log(value);
				var date = new Date(parseInt(value));
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth()+1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var D = date.getDate() + ' ';
				var h = date.getHours() + ':';
				var m = date.getMinutes() + ':';
				var s = date.getSeconds();
				var df = Y+M+D+h+m+s;
				console.log(df);
				return df;
			},
		}

此时,前台接收到的就是正常的年月日格式了。
在这里插入图片描述
如有不明白之处,欢迎留言。

Logo

前往低代码交流专区

更多推荐