剑轩

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

电脑版发表于:2019/9/28 17:37

也可以借助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



关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢