util.ts 748 B

123456789101112131415161718192021222324252627282930
  1. export const formatTime = (date: 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 (
  9. [year, month, day].map(formatNumber).join('/') +
  10. ' ' +
  11. [hour, minute, second].map(formatNumber).join(':')
  12. )
  13. }
  14. /// 格式化日期
  15. export function formatDate(date: Date) {
  16. date = new Date(date);
  17. return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  18. }
  19. const formatNumber = (n: number) => {
  20. const s = n.toString()
  21. return s[1] ? s : '0' + s
  22. }
  23. /// 判断字符串是否为空
  24. export const isnullstr = (str: string) => {
  25. return str == '' ? '--' : str
  26. }