火箭军大屏html静态页面
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.

50 lines
1.6 KiB

  1. function getCurrentTime() {
  2. const yy = new Date().getFullYear()
  3. const mm = new Date().getMonth() + 1
  4. const dd = new Date().getDate()
  5. const hh = new Date().getHours()
  6. const mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
  7. const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
  8. const time = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
  9. return time
  10. }
  11. function parseTime(time, cFormat) {
  12. if (arguments.length === 0) {
  13. return null
  14. }
  15. var format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  16. var date
  17. if (typeof time === 'undefined' || time === null || time === 'null') {
  18. return ''
  19. } else if (typeof time === 'object') {
  20. date = time
  21. } else {
  22. if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
  23. time = parseInt(time)
  24. }
  25. if ((typeof time === 'number') && (time.toString().length === 10)) {
  26. time = time * 1000
  27. }
  28. date = new Date(time)
  29. }
  30. const formatObj = {
  31. y: date.getFullYear(),
  32. m: date.getMonth() + 1,
  33. d: date.getDate(),
  34. h: date.getHours(),
  35. i: date.getMinutes(),
  36. s: date.getSeconds(),
  37. a: date.getDay()
  38. }
  39. const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
  40. var value = formatObj[key]
  41. // Note: getDay() returns 0 on Sunday
  42. if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
  43. if (result.length > 0 && value < 10) {
  44. value = '0' + value
  45. }
  46. return value || 0
  47. })
  48. return time_str
  49. }