xe-utils
Version:
JavaScript 函数库、工具类
17 lines (15 loc) • 537 B
JavaScript
import helperDateGetTime from './helperDateGetTime.js';import now from './now.js';import toStringDate from './toStringDate.js';import isDate from './isDate.js';/**
* 将日期格式化为时间戳
*
* @param {String/Number/Date} str 日期或数字
* @param {String} format 解析日期格式
* @returns Number
*/
var timestamp = function (str, format) {
if (str) {
var date = toStringDate(str, format)
return isDate(date) ? helperDateGetTime(date) : date
}
return now()
}
export default timestamp