| | |
Gregorian Calendar program
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 34
Reputation:
Solved Threads: 0
I am trying to execute this program, but I am getting errors
this is the code
I am testing this with
The first code compiled fine. But I am having errors with the second one.
How should I correct the 3 errors?
this is the code
Java Syntax (Toggle Plain Text)
import java.util.*; public class DateUtils { static final int MILLS_IN_DAY = 24*60*60*1000; public static Date getCurrentDate() { GregorianCalendar currentDate = new GregorianCalendar(); currentDate.set(Calendar.HOUR,0); currentDate.set(Calendar.MINUTE,0); currentDate.set(Calendar.SECOND,0); return currentDate.getTime(); } public static Date createDate(int year, int month, int day) { GregorianCalendar date = new GregorianCalendar(year,month,day); return date.getTime(); } public static Date stripTime(Date date) { GregorianCalendar currentDate = new GregorianCalendar(); currentDate.setTime(date); currentDate.set(Calendar.HOUR,0); currentDate.set(Calendar.MINUTE,0); currentDate.set(Calendar.SECOND,0); return currentDate.getTime(); } public static int daysDiff(Date date1, Date date2) { date1 = stripTime(date1); date2 = stripTime(date2); long longDate1=date1.getTime(); long longDate2=date2.getTime(); long longDiff = longDate2 - longDate1; return (int)(longDiff/MILLS_IN_DAY); } }
I am testing this with
Java Syntax (Toggle Plain Text)
import java.util.*; public class Tes{ public static void main(String[] args) { GregorianCalendar currentGC = new GregorianCalendar(); int currentYear = currentGC.get(Calendar.YEAR); Date currentDate = DateUtils.getCurrentDate(); Date christmas = DateUtils.createDate(currentYear,Calendar.DECEMBER,25); int daysToChristmas = DateUtils.daysDiff(currentDate, christmas); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); String formattedDate = dateFormat.format(currentDate); System.out.println("Today" + formattedDate); System.out.println("There are"+daysToChristmas); } }
The first code compiled fine. But I am having errors with the second one.
Java Syntax (Toggle Plain Text)
Tes.java:11: cannot find symbol symbol : class DateFormat location: class Tes DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); ^ Tes.java:11: cannot find symbol symbol : variable DateFormat location: class Tes DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); ^ Tes.java:11: cannot find symbol symbol : variable DateFormat location: class Tes DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); ^ 3 errors
How should I correct the 3 errors?
When do you think the compile time error 'symbol not found comes up'? What does your text book say about such errors? The example you posted seems a pretty bold one for someone who has just started out with Java.
Anyways, the error message means that the compiler doesn't know about the token 'DateFormat'; `import' the class in question and you should be good to go.
Anyways, the error message means that the compiler doesn't know about the token 'DateFormat'; `import' the class in question and you should be good to go.
I don't accept change; I don't deserve to live.
Sacrifice is a painful, pure and beautiful thing.
Sacrifice is a painful, pure and beautiful thing.
•
•
Join Date: Feb 2009
Posts: 34
Reputation:
Solved Threads: 0
Thanks for the help. It is working now. I know that this is pretty bold for a beginner. But I am understanding the concept behind it and I think that by understanding more such programs I will be able to become better with time.
With the internet and helpful communities like these willing to give a helping hand, I am sure I can improve myself.
With the internet and helpful communities like these willing to give a helping hand, I am sure I can improve myself.
![]() |
Similar Threads
- The Gregorian Calendar (C++)
- New to C program code to calculate age (C)
- leap year program (C++)
- gregorian calendar, help (C)
- Calendar Creator (C)
Other Threads in the Java Forum
- Previous Thread: Installer Files..
- Next Thread: Looping through different sets
Views: 1846 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application arguments array arrays binary bluetooth c++ chat class classes client code combobox compiler component converter coordinates data database db design desktop detection draw eclipse error event exception fast file fractal game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inheritance input integer interface j2me java javaprojects jmf jpanel jtable jtextfield julia linux list loop map method methods mobile netbeans newbie number object objects oracle os pattern print problem program programming read recursion regex remove robot scanner screen search server set size sms sort sql string swing test text threads time timer tree update windows






