util.wxs 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function formatTime (time) {
  2. var h = Math.floor(time / 60 /60)
  3. var s = Math.floor(time / 60)
  4. var t = time % 60 % 60
  5. return (h>9?h:'0'+h)+':'+(s>9?s:'0'+s)+':'+(t>9?t:'0'+t)
  6. }
  7. function valueOf (time=null) {
  8. var regexp = getRegExp('-','g');
  9. var t = time ? (getDate(time).valueOf() || getDate(time.replace(regexp,'/')).valueOf()) : getDate().valueOf()
  10. return t
  11. }
  12. function isIncludes (val,str) {
  13. return val && val.indexOf(str)!==-1
  14. }
  15. function toFixed (val,num) {
  16. return val.toFixed(num)
  17. }
  18. function shuffle(arr) {
  19. for (var i=arr.length-1; i>=0; i--) {
  20. var rIndex = Math.floor(Math.random()*(i+1));
  21. // 打印交换值
  22. // console.log(i, rIndex);
  23. var temp = arr[rIndex];
  24. arr[rIndex] = arr[i];
  25. arr[i] = temp;
  26. }
  27. return arr;
  28. }
  29. module.exports = {
  30. formatTime: formatTime,
  31. valueOf: valueOf,
  32. shuffle: shuffle,
  33. toFixed: toFixed,
  34. isIncludes: isIncludes
  35. }