...
|
...
|
@@ -10,24 +10,25 @@ import moment from 'moment'; |
|
|
* timeFormat({time: 1495787643})
|
|
|
* timeFormat({time: 1495787643, format: moment支持的format格式'})
|
|
|
*/
|
|
|
export default (value) => {
|
|
|
export default value => {
|
|
|
if (+value <= 0) {
|
|
|
return '';
|
|
|
}
|
|
|
let format;
|
|
|
let unixStamp;
|
|
|
const isNum = _.isFinite(value);
|
|
|
const isObj = _.isPlainObject(value);
|
|
|
const defaultFmt = 'YYYY-MM-DD HH:mm:ss';
|
|
|
|
|
|
let format;
|
|
|
let unixStamp;
|
|
|
const isNum = _.isFinite(value);
|
|
|
const isObj = _.isPlainObject(value);
|
|
|
const defaultFmt = 'YYYY-MM-DD HH:mm:ss';
|
|
|
if (isNum) {
|
|
|
unixStamp = value;
|
|
|
format = defaultFmt;
|
|
|
} else if (isObj) {
|
|
|
unixStamp = value.time;
|
|
|
format = value.format || defaultFmt;
|
|
|
} else {
|
|
|
unixStamp = 'Invalid value.';
|
|
|
}
|
|
|
|
|
|
if (isNum) {
|
|
|
unixStamp = value;
|
|
|
format = defaultFmt;
|
|
|
} else if (isObj) {
|
|
|
unixStamp = value.time;
|
|
|
format = value.format || defaultFmt;
|
|
|
} else {
|
|
|
unixStamp = 'Invalid value.';
|
|
|
}
|
|
|
|
|
|
return moment.unix(unixStamp).format(format);
|
|
|
return moment.unix(unixStamp).format(format);
|
|
|
}; |
|
|
|
...
|
...
|
|