util.js 716 B

123456789101112131415161718192021222324252627282930313233
  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. function json2Form(json) {
  15. var str = [];
  16. for(var p in json){
  17. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
  18. }
  19. return str.join("&");
  20. }
  21. module.exports = {
  22. formatTime,
  23. json2Form:json2Form,
  24. }
  25. // module.exports = {
  26. // json2Form:json2Form,
  27. // }