×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    date and time in CLDC1.0

    hi
    i am using this method to get date and time in my midlet..its working fine in CLDC1.1
    but when in CLDC1.0 phone its not showing the date and time properly
    can anyone help me on this

    Date d = new Date();
    Calendar c = Calendar.getInstance();

    DateField currentDate=new DateField("",DateField.DATE_TIME);

    currentDate.setDate(d);
    c.setTime(d);
    String date=d.toString();
    int month = c.get(Calendar.MONTH) + 1;
    String mon=Integer.toString(month);
    if(month<10){
    mon="0"+mon;
    }
    StringBuffer sb=new StringBuffer(mon);//Nov
    sb.append(date.substring(8,10));//Day
    sb.append(c.get(Calendar.YEAR));//Year
    sb.append(date.substring(11,13));//Hour
    sb.append(date.substring(14,16));//Min
    sb.append(date.substring(17,19));//Sec
    return sb.toString();

    Thanks in Advance
    Bejoy A K

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: date and time in CLDC1.0

    Date.toString() is your problem. The format of the String returned from this is specified only in CLDC-1.1, so you cannot rely on which field is in which characters on CLDC-1.0. Use Calendar.get() (as you are for YEAR and MONTH) to get the values of DAY_OF_WEEK, HOUR_OF_DAY, MINUTE and SECOND.

    Graham.

Similar Threads

  1. Scheduling some task for future Date and Time
    By vinay_saraswat in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2010-01-06, 10:13
  2. Scheduling a task for some future Date & time
    By vinay_saraswat in forum General Development Questions
    Replies: 3
    Last Post: 2009-12-31, 13:02
  3. Issue regarding date and time
    By himsymbian in forum Symbian
    Replies: 15
    Last Post: 2009-01-21, 10:57
  4. Date & Time Editor in Form Resource.
    By Kavit Patel in forum Symbian
    Replies: 2
    Last Post: 2008-03-03, 06:26
  5. Replies: 0
    Last Post: 2008-01-03, 17:58

Posting Permissions

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