React时间组件(时分秒补0)页面全局引用

1.common.js
export function formatTime(data){
var d = new Date(data);
function doTime(d){
if(d<10){
d='0'+d;
}
return d;
}
var times=d.getFullYear() + '-' + doTime((d.getMonth() + 1)) + '-' + doTime(d.getDate()) + ' ' + doTime(d.getHours()) + ':' + doTime(d.getMinutes()) + ':' + doTime(d.getSeconds());
return times;
}
 
2.页面引用
import {formatTime} from '../../common/timedeal';
<dd>{tData.lastEditTime ? formatTime(tData.lastEditTime) : '-'}</dd>
posted @ 2019-01-15 17:10  刘丑丑鱼香肉丝  阅读(704)  评论(0编辑  收藏  举报