mock平台

util.js 713B

1234567891011121314151617181920212223242526
  1. // 时间
  2. const convert2Decimal = num => (num > 9 ? num : `0${num}`);
  3. /**
  4. * 格式化 年、月、日、时、分、秒
  5. * @param val {Object or String or Number} 日期对象 或是可new Date的对象或时间戳
  6. * @return {String} 2017-01-20 20:00:00
  7. */
  8. exports.formatDate = val => {
  9. let date = val;
  10. if (typeof val !== 'object') {
  11. date = new Date(val);
  12. }
  13. return `${[
  14. date.getFullYear(),
  15. convert2Decimal(date.getMonth() + 1),
  16. convert2Decimal(date.getDate())
  17. ].join('-')} ${[
  18. convert2Decimal(date.getHours()),
  19. convert2Decimal(date.getMinutes()),
  20. convert2Decimal(date.getSeconds())
  21. ].join(':')}`;
  22. };
  23. // const json5_parse = require('../client/common.js').json5_parse;