JTextField时间在HH:mm:ss [英] JTextField time in HH:mm:ss
问题描述
HH:mm:ss
?格式
对象 - 您可以传递一个 DateFormat
您可以通过调用 DateFormat#getTimeInstance()
。您也可以使用 SimpleDateFormat
与 HH:mm:ss
作为格式字符串 如果你不限于使用 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屋!