This discussion is archived
6 Replies Latest reply: Apr 10, 2008 9:23 AM by 807601 RSS

date issue - mis

807601 Newbie
Currently Being Moderated
I have this function

      public GregorianCalendar getNowTime(){
                        GregorianCalendar c = new GregorianCalendar();
                        return c.getTime();
                    }
but I receive this error on return c.getTime();

java:462: incompatible types

found : java.util.Date
required: java.util.GregorianCalendar
return c.getTime();
  • 1. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    javanoobee wrote:
    java:462: incompatible types

    found : java.util.Date
    required: java.util.GregorianCalendar
    return c.getTime();
    Try to interpret the errror message. What could it possibly mean?
  • 2. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    What's the return type of getTime?
  • 3. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    I thought that .getTime() was a function built into java.

    when I do this
    GregorianCalendar c = new GregorianCalendar ();
              System.out.println("Todays Date : "+c.getTime());
    I'm assuming that the .getTime doesn't return a GregCal time?

    is there a way to get the current time using the GregCal if I can't use the .getTime()?
  • 4. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    javanoobee wrote:
    I thought that .getTime() was a function built into java.

    when I do this
    GregorianCalendar c = new GregorianCalendar ();
              System.out.println("Todays Date : "+c.getTime());
    I'm assuming that the .getTime doesn't return a GregCal time?

    is there a way to get the current time using the GregCal if I can't use the .getTime()?
    Y'all will want to bookmark this: [http://java.sun.com/javase/6/docs/api/]
  • 5. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    javanoobee wrote:
    I'm assuming that the .getTime doesn't return a GregCal time?
    Stop assuming and look it up: http://java.sun.com/javase/6/docs/api/

    There's some perfectly fine documentation that will tell you the return type of getTime().

    Also, the error message tells you the actual return type.
    is there a way to get the current time using the GregCal if I can't use the .getTime()?
    Possibly, check the documentation. Also, you should not hardcode the usage of GregorianCalendar in your code. Use Calendar.getInstance() instead (also read the documentation for that method, it will help you in your current problem).
  • 6. Re: date issue - mis
    807601 Newbie
    Currently Being Moderated
    JoachimSauer wrote:
    Also, you should not hardcode the usage of GregorianCalendar in your code. Use Calendar.getInstance() instead
    Indeed. Your code stops me from obtaining my platform's default calendar, the Thai Buddhist calendar, you bad man racist!