| | |
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});
•
•
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
Views: 2058 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Java
account android api apple applet application arguments array arrays automation binary bluetooth calculator chat class classes client code component data database draw eclipse error errors event exception file filechooser fractal game givemetehcodez google graphics gui helpwithhomework homework html ide image inheritance input integer j2me java javaprojects jlabel jmf jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception number object open-source oracle print problem program programming project property recursion ria scanner screen search server set size sms socket sort sourcelabs splash sql sqlite static string support swing test testautomation threads time transfer tree windows






