×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation date formating in j2me (urgent)

    i am getting date value as string from server in this way

    Date = 13,01,2010
    Time = 15,00

    i have to display it on DateField , in the form of date , so that user can edit it .

    thanks and regards
    Arunesh

  2. #2
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: date formating in j2me (urgent)

    J2ME does not support the DateFormat, You can just change it.

    User can use the date application on the device.

    Best regards,

  3. #3
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    i am using the following code for my work

    Calendar cal = Calendar.getInstance();

    cal.set(Calendar.DATE,date);
    cal.set(Calendar.MONTH,month);
    cal.set(Calendar.YEAR,year);
    cal.set(Calendar.HOUR,hour);
    cal.set(Calendar.MINUTE,min);
    long mili = cal.get(Calendar.MILISECONDS);
    long m = Calendar.getTimeInMillis();
    //dateField1.setDate(new java.util.Date(System.currentTimeMillis()));
    System.out.println(cal.get(Calendar.DATE)+" "+cal.get(Calendar.MONTH)+" "+cal.get(Calendar.YEAR)+" "+cal.get(Calendar.MILLISECOND));
    Date f = new Date(mili);
    System.out.println("date provided by server = "+f);

    but this line is showing error:
    long mili = cal.get(Calendar.MILISECONDS);
    if this works then i hope my work will be done.

    thanks and regards
    Arunesh

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

    Re: date formating in j2me (urgent)

    What error is it showing? That there is no such field as "MILISECONDS"? Check your spelling...

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    Actally that is also an error (i have deleted it)

    when i am using
    Date f = new Date(cal.getTimeInMillis());

    compiler is saying that "getTimeInMillis()" has protected scope

    and
    cal.get(Calendar.MILLISECOND)
    return 0.

    please help me

    thanks and regards
    Arunesh

  6. #6
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    i have used

    long mili = cal.getTime().getTime();

    instead of "gettimeinmilli" function , it worked for me

    thanks
    Arunesh

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

    Re: date formating in j2me (urgent)

    Quote Originally Posted by Arunesh View Post
    compiler is saying that "getTimeInMillis()" has protected scope
    Well, yes. Check the JavaDocs. This is not a public method. Use:

    Code:
    Date f = cal.getTime();
    Quote Originally Posted by Arunesh View Post
    and
    cal.get(Calendar.MILLISECOND)
    return 0.
    What value are you expecting? You don't set the milliseconds, so they're zero. Remember that Calendar.MILLISECOND does not refer to the total number of milliseconds, but to the number of milliseconds within the second (between 0 and 999).

    Graham.

  8. #8
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    my problem is not solved yet .. i don't know how it worked for the first time but now it is not working

    problem statement is as follows

    i get date and time from server in this format

    Date = 30,01,2010
    Time = 11,10

    and i have to show this date and time in "Datefield", so what i did is as follows

    int year = Integer.parseInt(date_in_Order[2]);
    int month = Integer.parseInt(date_in_Order[1]);
    int date = Integer.parseInt(date_in_Order[0]);
    int hour = Integer.parseInt(time_in_Order[0]);
    int min = Integer.parseInt(time_in_Order[1]);


    Calendar cal = Calendar.getInstance();

    cal.set(Calendar.DATE,date);
    cal.set(Calendar.MONTH,month);
    cal.set(Calendar.YEAR,year);
    cal.set(Calendar.HOUR,hour);
    cal.set(Calendar.MINUTE,min);

    now i have to get the date object from this calender so that i can display date in datefield in this form "dateField1.setDate(f);" where user will have privileged to do any modification in the date .

    for the purpose of getting date object i used this "Date f = cal.getTime();" but it is not working .

    i also tried

    long mili = cal.getTime().getTime();
    Date f = new Date(mili);

    but this also did't worked for me .. it says " java.lang.IllegalArgumentException".

    kindly guide me to solve the problem.

    thanks and regards
    Arunesh

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

    Re: date formating in j2me (urgent)

    Quote Originally Posted by Arunesh View Post
    for the purpose of getting date object i used this "Date f = cal.getTime();" but it is not working .
    In what way "not working"?

    Quote Originally Posted by Arunesh View Post
    long mili = cal.getTime().getTime();
    Date f = new Date(mili);

    but this also did't worked for me .. it says " java.lang.IllegalArgumentException".
    What says "IllegalArgumentException"? new Data(mili)?? Where is the exception being thrown?

  10. #10
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    1. "long mili = cal.getTime().getTime();" if i write this line i get Illegal exception
    2. and "Date f = cal.getTime();" throws Illegal exception

  11. #11
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    the detailed description of exception is as follows

    TRACE: <at java.lang.IllegalArgumentException>, Exception caught in Display class
    java.lang.IllegalArgumentException
    at com.sun.cldc.util.j2me.TimeZoneImpl.getOffset(), bci=76
    at com.sun.cldc.util.j2me.TimeZoneImpl.getOffset(), bci=33
    at com.sun.cldc.util.j2me.CalendarImpl.computeTime(), bci=295
    at java.util.Calendar.getTimeInMillis(Calendar.java:1082)
    at java.util.Calendar.getTime(), bci=13
    at SmartComm.GroupSMSOptionsAction(), bci=839
    at SmartComm.commandAction(SmartComm.java:847)
    at javax.microedition.lcdui.ChoiceGroupLFImpl.uCallKeyPressed(), bci=271
    at javax.microedition.lcdui.FormLFImpl.uCallKeyPressed(), bci=87
    at javax.microedition.lcdui.DisplayableLFImpl.uCallKeyEvent(), bci=146
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=30
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:619)

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

    Re: date formating in j2me (urgent)

    OK. One or more of the values you are setting into the Calendar's fields is invalid. Probably, the month is invalid. Exactly what are the values you are setting for each field? (You should get the code to display them, do not assume you know what they are.)

  13. #13
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    179

    Exclamation Re: date formating in j2me (urgent)

    i am really thankful to o you.

    Arunesh

Similar Threads

  1. URGENT: is there a pow() method in j2me?
    By rj_cybersilver in forum Mobile Java General
    Replies: 9
    Last Post: 2010-01-19, 09:39
  2. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. need urgent help:is awt package support in j2me?
    By avanidave in forum Mobile Java General
    Replies: 2
    Last Post: 2007-03-08, 13:28
  5. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32

Posting Permissions

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