主页

uniapp元素时间戳转换时间日期

回家丶洗洗睡吧   IP属地: 青海
0 点赞 0阅读 1030

代码:

filters: {
			formatDate: function(value) {
				var date = new Date(value*1000);
				var month = date.getMonth() + 1;
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}
		},

示例代码:

<template>
    <view>
		<empty v-if="!arr.length" style=""></empty>
        <!-- 审核员培训分类接口 -->
        <view class="manageAll">
            <view class="manageList" v-for="item in arr">
                <view class="manageText" style="width: 390rpx;">
                    <view class="title">{{item.title}}</view>
                    <!-- <view class="subtitle">{{item.subtitle}}</view> -->
					<view class="subtitle">考试时间:{{item.createtime | formatDate}}</view>
                </view>
				<view style="flex: 1;display: flex;flex-direction: column;text-align: center;">
					<view v-if="item['fraction']>=item['pass_mark']" style="color: #3B914F;font-size: 30rpx;">已通过</view>
					<view v-else style="color: red;font-size: 30rpx;">未通过</view>
				</view>
                <view class="isopen" @click="navClick('/pages/answer/result?log_id='+item.id+'&title='+item.title)">
						<view style="color:#AEAEAE">考试结果</view>
						<!-- <view style="color:#5863F5">去考试</view> -->
                </view>
            </view>
        </view>
        
    </view>
</template>

<script>
    export default {
        data() {
            return {
                arr:[],//管理体系
            }
        },
		filters: {
			formatDate: function(value) {
				var date = new Date(value*1000);
				var month = date.getMonth() + 1;
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}
		},
		onLoad(e){
			console.log(e)
		    this.getData();
			
		},
		onShow(){
		},
        onShareAppMessage() {
            
        },
		onPullDownRefresh() {
		   this.getData()
		},
        methods: {
            getData(){
				let that = this;
				uni.showLoading({
					title:'加载中...'
				})
				that.$request('/answer/answer_record', {}).then(res => {
					let data = res.data;
					that.arr = data
					uni.hideLoading();
				});
            },
            //菜单选择
			menuSelect(index){
				this.menuSelectIndex=index;
			},
            navClick(url){
                uni.navigateTo({
                    url:url
                })
            },
            
        }
    }
</script>

<style scoped>
    
    .scroll{
        width: 750rpx;
        height: 80rpx;
        line-height: 100rpx;
        display: flex;
        align-items: center;
        background: #5564F5;
    }
    .scroll image{
        width: 38rpx;height: 29rpx;
        margin: 0 0rpx 0 20rpx;
    }
    .scrollText{
        color: white;
        font-size: 30rpx;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
    }
    .carousel{
        width: 710rpx;
        margin: 15rpx auto;
        height: auto;
        border-radius: 10rpx;
    }
    .carouselse{
        width: 100%;height: 100%;
    }
    .materialAll{
        width: 750rpx;
        margin: 30rpx 0;
		margin-top: 50rpx;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
        align-items: center;
    }
    .exam{
        width: 130rpx;
        height: 120rpx;
        text-align: center;
    }
    .exam image{
        width: 75rpx;height: 75rpx;
        border-radius: 10rpx;
    }
    .exam .examText{
        font-size: 24rpx;
    }
    .signUp{
        width: 750rpx;
        height: 150rpx;
        background: white;
        display: flex;align-items: center;
    }
    .signUpText{
        width: 670rpx;
        height: 80rpx;
        margin: 0 auto;font-size: 33rpx;
        border-radius: 50rpx;
        text-align: center;line-height: 80rpx;
        color: white;
        background-image: -webkit-gradient(linear,left bottom,right bottom,color-stop(0,#3849D5),color-stop(1,#48A4DE));
    }
    .manageAll{
        width: 100%;
        height: auto;
        min-height: 300rpx;
        margin: 30rpx 0;
        padding:30rpx 0;
        box-sizing: border-box;
		display: flex;
		flex-direction: column;
		margin-top: 0;
    }
    .manageList{
        width: 96%;
        /* border-bottom: #D3D3D3 1rpx solid; */
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        align-items: center;
		padding: 15rpx 0;
		
		background: white;
		padding: 10rpx 15rpx;
		box-sizing: border-box;
		border-radius: 7rpx;
		margin-bottom: 15rpx;
    }
    .manageList .manageImg{
        width: 295rpx;
        height: 165rpx;
        border-radius: 10rpx;
		margin-right: 20rpx;
    }
    .manageText{
        /* height: 180rpx; */
    }
    .manageText .title{
		font-size: 32rpx;
		margin-top: 10rpx;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        font-weight: bolder;
        margin-bottom: 10rpx;
    }
    .manageText .subtitle{
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        font-size: 25rpx;
        margin-bottom: 20rpx;color: #808080;
    }
    .isopen{
        /* line-height: 220rpx; */
        font-size: 25rpx;color: #797979;
    }
    .isopen image{
        width: 45rpx;height: 45rpx;
        margin-bottom: -16rpx;
        margin-left: 10rpx;
    }
</style>


© 著作权归作者所有,转载或内容合作请联系作者