timestamp.js 526 B

1234567891011121314151617181920212223
  1. var helperGetDateTime = require('./helperGetDateTime')
  2. var now = require('./now')
  3. var toStringDate = require('./toStringDate')
  4. var isDate = require('./isDate')
  5. /**
  6. * 将日期格式化为时间戳
  7. *
  8. * @param {String/Number/Date} str 日期或数字
  9. * @param {String} format 解析日期格式
  10. * @returns Number
  11. */
  12. var timestamp = function (str, format) {
  13. if (str) {
  14. var date = toStringDate(str, format)
  15. return isDate(date) ? helperGetDateTime(date) : date
  16. }
  17. return now()
  18. }
  19. module.exports = timestamp