You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

105 lines
3.2 KiB

  1. /**
  2. * @description 根据时间戳获取时间
  3. * @param {*} timestamp 必传,number类型,时间戳数据(10位及以下,10位至13位);若不传,则返回:“无时间戳”
  4. * @param {*} format 选传,string类型,提供以下时间格式:YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日;若不传,则默认为:YYYY-MM-DD
  5. * @returns 根据要求的时间格式
  6. * @version V 1.0, Created by YWQ, 2022.10.20
  7. */
  8. export const timestampToTime = (timestamp, format) => {
  9. //时间戳为10位需*1000,时间戳为13位不需乘1000
  10. const length = timestamp.length
  11. if (length <= 10) {
  12. var date = new Date(timestamp * 1000)
  13. } else {
  14. var date = new Date(timestamp)
  15. }
  16. let Y = String(date.getFullYear())
  17. let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  18. let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate())
  19. let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours())
  20. let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
  21. let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
  22. // return Y + M + D + h + m + s
  23. if (format == "YYYY-MM-DD hh:mm:ss") {
  24. return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s
  25. } else if (format == "YYYY/MM/DD hh:mm:ss") {
  26. return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s
  27. } else if (format == "YYYY.MM.DD hh:mm:ss") {
  28. return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s
  29. } else if (format == "YYYY MM DD hh:mm:ss") {
  30. return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s
  31. } else if (format == "YYYY年MM月DD日 hh:mm:ss") {
  32. return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s
  33. } else if (format == "YYYY-MM-DD") {
  34. return Y + "-" + M + "-" + D
  35. } else if (format == "YYYY/MM/DD") {
  36. return Y + "/" + M + "/" + D
  37. } else if (format == "YYYY.MM.DD") {
  38. return Y + "." + M + "." + D
  39. } else if (format == "YYYY MM DD") {
  40. return Y + " " + M + " " + D
  41. } else if (format == "YYYY年MM月DD日") {
  42. return Y + "年" + M + "月" + D + "日"
  43. } else {
  44. return Y + "-" + M + "-" + D
  45. }
  46. }
  47. /**
  48. * @description:滚动到对应id的位置
  49. * @param {type} id
  50. */
  51. export const scrollToID = id => {
  52. wx.createSelectorQuery().select("#" + id).scrollIntoView({
  53. behavior: "smooth",
  54. block: "start",
  55. inline: "nearest",
  56. });
  57. }
  58. /**
  59. * @description:命中标签枚举值
  60. * @return {string} 100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
  61. */
  62. export const keyWordsEnum = [
  63. // {
  64. // msg: '正常',
  65. // label: 100
  66. // },
  67. {
  68. msg: '广告',
  69. label: 10001
  70. },
  71. {
  72. msg: '时政',
  73. label: 20001
  74. },
  75. {
  76. msg: '色情',
  77. label: 20002
  78. },
  79. {
  80. msg: '辱骂',
  81. label: 20003
  82. },
  83. {
  84. msg: '违法犯罪',
  85. label: 20006
  86. },
  87. {
  88. msg: '欺诈',
  89. label: 20008
  90. },
  91. {
  92. msg: '低俗',
  93. label: 20012
  94. },
  95. {
  96. msg: '版权',
  97. label: 20013
  98. },
  99. // {
  100. // msg: '其他',
  101. // label: 21000
  102. // },
  103. ]