Results 1 to 3 of 3
  1. #1
    shurgs is offline Member
    Join Date
    Aug 2010
    Location
    England
    Posts
    12
    Rep Power
    0

    Default .DAY_OF_WEEK always returns 7

    Hi there, I'm setting a calendar to a date that's pulled from an array of results of a MySQL query stored in events[y][1].

    Java Code:
    GregorianCalendar eventdatecal = new GregorianCalendar(TimeZone.getTimeZone("Europe/London"),Locale.UK);
              Date eventdatesimple = simpledateform.parse(events[y][1]);
              eventdatecal.setTime(eventdatesimple);
                  System.out.println(eventdatecal); /*This returns 0->6, Sun->Sat for .DAY_OF_WEEK*/
              int xindex = eventdatecal.DAY_OF_WEEK;
                  System.out.println(xindex);/*But this always returns 7 :@*/
    The problem is this: If I add in System.out.println(eventdatecal); I can see that the DAY_OF_WEEK variable changes depending what date I get from events[y][1] and it's correct. But as soon a I try and pass it into xindex and System.out.println(xindex); it returns 7, every time. Am I doing something really silly or am I right in thinking this makes no sense?
    Last edited by shurgs; 08-20-2010 at 02:20 PM. Reason: typo

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default

    Hi,

    What you currently did is assigning the value of a constant field Calendar.DAY_OF_WEEK to the xindex variable. Calendar.DAY_OF_WEEK is an integer field that have a value 7. So you'll always get 7 printed out as the output.

    From your requirement your code should be:

    Java Code:
    int xindex = eventdatecal.get(Calendar.DAY_OF_WEEK);
    Last edited by wsaryada; 08-20-2010 at 02:31 PM.

  3. #3
    shurgs is offline Member
    Join Date
    Aug 2010
    Location
    England
    Posts
    12
    Rep Power
    0

Similar Threads

  1. IndexSearch.docfreq returns 0.0
    By noir in forum Lucene
    Replies: 0
    Last Post: 04-26-2010, 09:32 AM
  2. Carriage Returns in JTEXTAREA
    By AJArmstron@aol.com in forum Advanced Java
    Replies: 8
    Last Post: 04-17-2010, 07:34 PM
  3. String file and carriage returns
    By AJArmstron@aol.com in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 01:28 AM
  4. NetworkInterface returns only ports that are up
    By dogbert in forum Networking
    Replies: 0
    Last Post: 10-13-2009, 05:12 PM
  5. What's the need for co-variant returns ?
    By ajeeb in forum New To Java
    Replies: 0
    Last Post: 03-23-2009, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •