TimeUtils.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import moment from 'moment';
  2. function today() {
  3. return __DEV__
  4. ? '2020-06-17 00:00:00,2020-06-17 23:59:59'
  5. : moment().format('YYYY-MM-DD') +
  6. ' 00:00:00,' +
  7. moment().add(1, 'days').format('YYYY-MM-DD') +
  8. ' 00:00:00';
  9. }
  10. function getSearchDate(showDate) {
  11. return (
  12. showDate +
  13. ' 00:00:00,' +
  14. moment(showDate, 'yyyy-MM')
  15. .add(1, 'months')
  16. .add(-1, 'seconds')
  17. .format('yyyy-MM-DD') +
  18. ' 23:59:59'
  19. );
  20. }
  21. class MonthDate {
  22. constructor() {
  23. var list = [];
  24. for (let i = 0; i < 6; i++) {
  25. list.push(
  26. moment()
  27. .add(0 - i, 'months')
  28. .format('yyyy-MM')
  29. );
  30. }
  31. this.showList = list;
  32. }
  33. }
  34. function parse(date, formatStr = 'yyyy-MM-DD HH:mm:ss') {
  35. return moment(date, formatStr);
  36. }
  37. function getChatTime(date, formatStr = 'yyyy-MM-DD HH:mm:ss') {
  38. if (parse(date).format('yyyy-MM-DD') === moment().format('yyyy-MM-DD')) {
  39. return parse(date).format('HH:mm');
  40. } else {
  41. return parse(date).format('MM-DD HH:mm');
  42. }
  43. }
  44. export { today, MonthDate, getSearchDate, parse, getChatTime };