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>
原文地址:https://www.cnblogs.com/lj8023/p/10273013.html