Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateUtil between优化及formatBetween格式化精度丢失bug? #3546

Closed
pigeon-fancier opened this issue Apr 15, 2024 · 1 comment
Closed
Labels

Comments

@pigeon-fancier
Copy link

pigeon-fancier commented Apr 15, 2024

版本情况

JDK版本: openjdk_17.0.9
hutool版本: 5.7.26(已在5.7.27测试过,问题依旧存在)(请确保最新尝试是否还有问题)

问题描述(包括截图)

如下代码输出:

between1: 2332800
between2: 2332800
betweenFormat: 38分52秒

between希望可以加上符号表示区别,这样可以从判断日期大小转变成判断between跟0的值
formatBetween格式化精度丢失?
formatBetween格式化可以自己传入符号表示单位吗?现在写死中文,可以用字母h m等

  1. 复现代码
  public static void main(String[] args) {
      String start = "2024-04-02 08:52:00";
      String end = "2024-04-29 08:55:00";
      long between1 = DateUtil.between(DateUtil.parseDate(end),
              DateUtil.parseDate(start),
              DateUnit.SECOND);
      System.out.println("between1: " + between1);
      long between2 = DateUtil.between(DateUtil.parseDate(start),
              DateUtil.parseDate(end),
              DateUnit.SECOND);
      System.out.println("between2: " + between2);
      String betweenFormat = DateUtil.formatBetween(between2, BetweenFormatter.Level.SECOND);
      System.out.println("betweenFormat: " + betweenFormat);
  }
  1. 堆栈信息
    没有报错
  2. 测试涉及到的文件(注意脱密)

    比如报错的Excel文件,有问题的图片等。
@looly
Copy link
Member

looly commented Apr 15, 2024

  1. 加上符号表示区别指?没看懂啥意思,加什么符号?
  2. 你不应该使用parseDate,这样时分秒会归零(因为只解析日期,不解析时间),你应该使用parse方法。
  3. 考虑自行把关键字替换。

@looly looly closed this as completed Apr 15, 2024
@looly looly added the question label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants