| | |
String format
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 114
Reputation:
Solved Threads: 0
Hello all,
I am trying to display time in the following format that represents hours and minutes:
hh:mm
For some reason I keep getting the following error:
"The method format(String, Object[]) in the type String is not applicable for the arguments (String,
int, int)". Both time and minutes are integers. I am not sure what the problem could be. Any assistance will be appreciated.
Thanks Kim
I am trying to display time in the following format that represents hours and minutes:
hh:mm
Java Syntax (Toggle Plain Text)
public String getTime() { String time = String.format("%tI:%tM", hours, minutes); return time; }
For some reason I keep getting the following error:
"The method format(String, Object[]) in the type String is not applicable for the arguments (String,
int, int)". Both time and minutes are integers. I am not sure what the problem could be. Any assistance will be appreciated.
Thanks Kim
What is the datatype of hours, minutes variables?
As per java documentation the syntax of String.format is ...
If hours and minutes are int type,
As per java documentation the syntax of String.format is ...
Java Syntax (Toggle Plain Text)
public static String format(String format,Object... args)
Java Syntax (Toggle Plain Text)
String.format("%d:%d", hours, minutes); // or String.format("%d:%d", new Object[]{hours, minutes});
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Apr 2006
Posts: 114
Reputation:
Solved Threads: 0
There must be some sort of error in Eclipse, because it is the only one that gives this error. However, I moved over to JGrasp and it works fine with your solution.
Is there any way to add a 0 for the minutes to keep the time formatted properly?
For example: if minutes are less than 10 it should display 12:08 instead of 12:8
Thanks
Is there any way to add a 0 for the minutes to keep the time formatted properly?
For example: if minutes are less than 10 it should display 12:08 instead of 12:8
Thanks
![]() |
Similar Threads
- String.Format()?! Why is it used? (C#)
- how to add 2 dates that are in string format to get the next date (ASP.NET)
- how to add 2 dates that are in string format (ASP)
- Problem using String.Format inside Request.Form (ASP.NET)
- Need help with java string.format (prepayment calculation) (Java)
Other Threads in the Java Forum
- Previous Thread: How to login automatically in online accounts using java?
- Next Thread: Help with Database errors
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






