util.js 632 B

12345678910111213141516171819202122232425
  1. const formatTime = date => {
  2. var date = new Date(date);
  3. const year = date.getFullYear();
  4. const month = date.getMonth() + 1;
  5. const day = date.getDate();
  6. const hour = date.getHours();
  7. const minute = date.getMinutes();
  8. const second = date.getSeconds();
  9. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':');
  10. };
  11. const formatNumber = n => {
  12. n = n.toString();
  13. return n[1] ? n : '0' + n;
  14. };
  15. const getTimestamp = date => {
  16. var timestamp = Date.parse(date);
  17. return timestamp;
  18. };
  19. module.exports = {
  20. formatTime: formatTime,
  21. getTimestamp: getTimestamp
  22. };