美文网首页
element-ui表格日期格式化

element-ui表格日期格式化

作者: _借东西的小人 | 来源:发表于2023-05-23 14:29 被阅读0次
image.png
<el-table-column prop="dateNow" label="时间" :show-overflow-tooltip="true" width="150">
                    <template slot-scope="scope">
                        <span>{{dateFormat("YYYY-mm-dd HH:MM",scope.row.dateNow) }}</span>
                    </template>
                </el-table-column>
 dateFormat(format, date) {
            if (date == null) {
                return null;
            }
            let ret = "";
            date = new Date(date);
            const val = {
                "Y+": date.getFullYear().toString(), // 年
                "m+": (date.getMonth() + 1).toString(), // 月
                "d+": date.getDate().toString(), // 日
                "H+": date.getHours().toString(), // 时
                "M+": date.getMinutes().toString(), // 分
                "S+": date.getSeconds().toString(), // 秒
            };
            for (let k in val) {
                ret = new RegExp("(" + k + ")").exec(format);
                if (ret) {
                    format = format.replace(
                        ret[1],
                        ret[1].length == 1
                            ? val[k]
                            : val[k].padStart(ret[1].length, "0")
                    );
                }
            }
            return format;
        },

相关文章

网友评论

      本文标题:element-ui表格日期格式化

      本文链接:https://www.haomeiwen.com/subject/txuxedtx.html