util.js 1017 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * 工具类
  3. */
  4. class Util {
  5. static formatTime(date) {
  6. let year = date.getFullYear();
  7. let month = date.getMonth() + 1;
  8. let day = date.getDate();
  9. let hour = date.getHours();
  10. let minute = date.getMinutes();
  11. let second = date.getSeconds();
  12. return [year, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':');
  13. };
  14. static formatNumber(n) {
  15. n = n.toString();
  16. return n[1] ? n : '0' + n;
  17. };
  18. static distance = (la1, lo1, la2, lo2) => {
  19. var La1 = la1 * Math.PI / 180.0;
  20. var La2 = la2 * Math.PI / 180.0;
  21. var La3 = La1 - La2;
  22. var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
  23. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
  24. s = s * 6378.137; //地球半径
  25. s = Math.round(s * 1000) / 1000;
  26. // console.log("计算结果",s)
  27. return s
  28. }
  29. };
  30. module.exports = Util;