DateFormat Problem !!!
Hi:
Please, what ist here wrong ?
import java.text.*;
import java.util.*;
publicclass DateFormat
{
publicstaticvoid main(String[] args)
{
GregorianCalendar gc =new GregorianCalendar(2001, Calendar.AUGUST, 15);
print(gc, java.text.DateFormat.SHORT);
print(gc, java.text.DateFormat.MEDIUM);
}
staticvoid print(Calendar c,int style)
{
DateFormat dfDate = DateFormat.getDateInstance(style);
//System.out.print(dfDate.format(c.getDate()) + " / ");
DateFormat dfTime = DateFormat.getTimeInstance(style);
//System.out.print(dfTime.format(c.getTime()));
}
}
If I try to compile code, I get following error message:
DataFormat.java: 16 cannot resolve symbol
symbol: method getDateInstance (int)
location:class DateFormat
DateFormat dfDate = DateFormat.getDateInstance(style);
DataFormat.java: 18 cannot resolve symbol
symbol: method getDateInstance (int)
location:class DateFormat
DateFormat dfTime = DateFormat.getDateInstance(style);
What is wrong ? Thanks in advace !
[1892 byte] By [
manjaca] at [2007-9-26 4:07:55]

Hi! Just Change your class name...Hope this help!Miller
The name of your class is conflicting with the DateFormat class in the java.text package. Either rename your class or fully qualify the DateFormat's used in your print() method as you did in your main() method: "DateFormat" --> "java.text.DateFormat".
> Hi!
>
> Just Change your class name...
>
> Hope this help!
>
> Miller
Thanks for replay:
I did it, but it doesn't work to!
import java.util.*;
import java.text.*;
public class DateFormatTest
{
public static void main(String[] args)
{
GregorianCalendar gc = new GregorianCalendar(2001, Calendar.AUGUST, 15);
print(gc, java.text.DateFormat.SHORT);
print(gc, java.text.DateFormat.MEDIUM);
}
static void print(Calendar c, int style)
{
DateFormat dfDate = DateFormat.getDateInstance(style);
System.out.print(dfDate.format(c.getDate()) + " / ");
DateFormat dfTime = DateFormat.getTimeInstance(style);
System.out.print(dfTime.format(c.getTime()));
}
}
And if I write java.text.DateFormat ...
static void print(Calendar c, int style)
{
java.text.DateFormat dfDate = java.text.DateFormat.getDateInstance(style);
//System.out.print(dfDate.format(c.getDate()) + " / ");
java.text.DateFormat dfTime = java.text.DateFormat.getTimeInstance(style);
//System.out.print(dfTime.format(c.getTime()));
}
I can compile. But, what is with import.text.*;
line? And if I do it so, I have a problem with following:static void print(Calendar c, int style)
{
java.text.DateFormat dfDate = java.text.DateFormat.getDateInstance(style);
System.out.print(dfDate.format(c.getDate()) + " / ");
java.text.DateFormat dfTime = java.text.DateFormat.getTimeInstance(style);
System.out.print(dfTime.format(c.getTime()));
}
DateFormatTest.java:18: cannot resolve symbol
symbol : method getDate ()
location: class java.util.Calendar
System.out.print(dfDate.format(c.getDate()) + " / ");
Any other idea?
The Calendar class does not have the method getDate() , try using getTime() here instead.
Thanks, it was my mistake. I execute this program now with NetBeans and it works fine (after change of getDate()-->getTime()). And with Kawa 4.01 it doesn't work. Any idea?
Dear all, I think, something was wrong mit my IDE. I deleted all orders and files and created again new project with new class. And my program works.Thanks a lot for help!
hey... mind if i borrow some of your genuises for a while... how do you use both Gregorian Calendar & the DateFormat thingy? I'm currently doing an assignment which requires me to retrieve the computer's current date and to do calculation for the next 14 days... Someone please teach me... If can, send the source code to zonkmaster@skali.com...
Thanks for your guidance... really appreciate it...
Hi.
You can use the add method to make this:
Example:
GregorianCalendar m_calendar;
TimeZone tz = TimeZone.getTimeZone("PNT");
Calendar Fecha = new GregorianCalendar(tz);
for (int i=1;i<15;i++){
Fecha.add(Calendar.DATE, 1);
//You can format as you need
System.out.print(Fecha.get(Calendar.DAY_OF_MONTH));
System.out.print(Fecha.get(Calendar.MONTH));
System.out.println(Fecha.get(Calendar.YEAR));
}
or you can only add 14 days directly.
Fecha.add(Calendar.DATE,14);
Hope this helps
thanks for the help, guys... I really appreciate it a lot..