gpt4 book ai didi

java - 将 GWT 中的时间值格式化为 HH :mm:ss. SS

转载 作者:行者123 更新时间:2023-12-01 17:25:22 25 4
gpt4 key购买 nike

我的时间格式如下

 public static final String TIME_FORMAT = "HH:mm:ss.SS";
edition.getEditionDate().format(TIME_FORMAT);

输出如下:

15:02:08.293

我应该如何获得以下输出。我不想使用Joda Time 。我不想使用 substring() 方法,因为它不是一种有效的方法。

15:02:08.29

无法使用 SimpleDateFormat,因为 Gwt 客户端代码不支持。 Methods supported by GWT client side code

最佳答案

SimpleDateFormat dateFormat = new SimpleDateFormat ("HH:MM:ss.");
DecimalFormat fractionalformat = new DecimalFormat ("00");

Date date = new Date ();

String str = dateFormat.format (date) + fractionalformat.format (date.getTime () % 1000L / 10L);

System.out.println (str);

关于java - 将 GWT 中的时间值格式化为 HH :mm:ss. SS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com