JTextField时间在HH:mm:ss [英] JTextField time in HH:mm:ss

查看:186
本文介绍了JTextField时间在HH:mm:ss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有估计的时间,它将花费几分钟的时间完成一个特定的任务。我怎样才能把它放在一个JFormattedTextField格式为 HH:mm:ss

解决方案 JFormattedTextField 接受一个格式对象 - 您可以传递一个 DateFormat 您可以通过调用 DateFormat#getTimeInstance() 。您也可以使用 SimpleDateFormat HH:mm:ss 作为格式字符串



另请参阅:
http://download.oracle .com / javase / tutorial / uiswing / components / formattedtextfield.html#format




如果你不限于使用 JFormattedTextField ,您也可以考虑使用 TimeUnit 类,自Java 1.5起可用,如此答案中所示:如何将毫秒转换为&现状t; X分钟,x秒在Java?


I have the estimated time the it would take for a particular task in minutes in a float. How can I put this in a JFormattedTextField in the format of HH:mm:ss?

解决方案

JFormattedTextField accepts a Format object - you could thus pass a DateFormat that you get by calling DateFormat#getTimeInstance(). You might also use a SimpleDateFormat with HH:mm:ss as the format string.

See also: http://download.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html#format


If you're not restricted to using a JFormattedTextField, you might also consider doing your own formatting using the TimeUnit class, available since Java 1.5, as shown in this answer: How to convert Milliseconds to "X mins, x seconds" in Java?

这篇关于JTextField时间在HH:mm:ss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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