将String转换为Joda LocalTime格式(HH:mm:ss)并删除毫秒 [英] Convert String to Joda LocalTime format (HH:mm:ss) and Remove milliseconds

查看:1173
本文介绍了将String转换为Joda LocalTime格式(HH:mm:ss)并删除毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm:ss");
LocalTime localTime = fmt.parseLocalTime("02:51:20");
System.out.println("LocalTime:            "+localTime);

我只需要02:51:20,但输出为02:51:20.000。有什么方法可以从输出中删除.000(毫秒)。

I need only 02:51:20 but it outputs as 02:51:20.000. Is there any way that I can remove the .000 (milliseconds) from the output.

推荐答案

是的 - 你只需要格式化当你打印出来。目前,您只是使用默认的 toString()表示。如果您对已经使用的格式化程序感到满意,可以使用:

Yes - you just need to format when you print out. Currently you're just using the default toString() representation. If you're happy with the formatter you've already got, you can just use:

System.out.println("LocalTime:            " + fmt.print(localTime));

这篇关于将String转换为Joda LocalTime格式(HH:mm:ss)并删除毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆