util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const formatTime = date => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
  9. }
  10. const formatNumber = n => {
  11. n = n.toString()
  12. return n[1] ? n : `0${n}`
  13. }
  14. // const baseUrl = 'https://hui.yrslm.com:8089/';
  15. const baseUrl = 'http://192.168.0.13:8157/';
  16. function js_date_time(unixtime) {
  17. var dateTime = new Date(parseInt(unixtime))
  18. var year = dateTime.getFullYear();
  19. var month = dateTime.getMonth() + 1;
  20. var day = dateTime.getDate();
  21. var hour = dateTime.getHours();
  22. var minute = dateTime.getMinutes();
  23. var second = dateTime.getSeconds();
  24. var now = new Date();
  25. var now_new = Date.parse(now.toDateString()); //typescript转换写法
  26. var milliseconds = now_new - dateTime;
  27. var timeSpanStr = year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
  28. return timeSpanStr;
  29. }
  30. module.exports = {
  31. formatTime,
  32. baseUrl,
  33. js_date_time
  34. }