故如虹,知恩;故如月,知明
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

js时间格式化,vue.js时间格式化,带T 时间格式化

10004人阅读 2019/9/28 17:37 总访问:3937421 评论:2 收藏:0 手机
分类: 前端

也可以借助moment库, 参考:https://www.tnblog.net/aojiancc2/article/details/8079

moment库有点大,推荐可以使用day.js

官网:https://dayjs.fenxianglu.cn/

Element-plus中可以直接使用:

import { dayjs } from 'element-plus'

参考:day.js 获取上月,当月,下月 - 只若初见的专栏 - TNBLOG



时间格式:/Date(1567138282927)/


js格式化为日期格式:

new Date(parseInt('/Date(1567138282927)/'.substr(6, 13)));

js格式化为短日期格式:

new Date(parseInt('/Date(1567138282927)/'.substr(6, 13))).toLocaleDateString();

其他格式就同理


js json 带T 时间格式化 

//处理时间
function ChangeDateFormat(jsondate) {
        var date = new Date(jsondate).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
}


vue中带T 时间格式化 可以这样使用

先定义方法:

methods: {
    changeDateFormat(jsondate) {
        var date = new Date(jsondate).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
        return date;
    }

然后绑定的时候直接调用方法就行

<div class="deal-time">
     处理时间:{{changeDateFormat(item.dealTime)}}
</div>

表格中时间格式化可以这样使用

<el-table-column label="时间" width="190">
    <template #default="{ row }">
        {{changeDateFormat(row.eventsTime)}}
    </template>
</el-table-column>


vue.js中还可以使用一个过滤器实现:

filters: {
    formatDate: function (time) {
        var date = new Date(parseInt(time.substr(6, 13))).toLocaleDateString();
        return date;
    }
}

使用

{{item.CreateTime|formatDate}}


.net core3.0 json时间格式化参考:http://www.tnblog.net/aojiancc/article/details/3347



欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价