×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    26

    Question How to get 24 hours date time format in J2ME ?

    Hi,

    Can anyone help me to get 24 hours Date-Time format which I can send to a date field on remote MySQL server through network.

    Help with code and example will be appreciated.

    Thanks in advance.

  2. #2
    Regular Contributor
    Join Date
    Dec 2011
    Posts
    174

    Re: How to get 24 hours date time format in J2ME ?

    Hi maaz4,

    Here's a link for an example how to get date and time

    http://www.developer.nokia.com/Commu...ime_in_Java_ME

    Regards,
    tiviinik

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    26

    Re: How to get 24 hours date time format in J2ME ?

    thanks for your help sir.

    but when I use

    " Date date = new Date(); "

    I am getting 12-hours format date. How can I get 24-hours format ? Does this depends on phone time format ?

  4. #4
    Registered User
    Join Date
    Feb 2007
    Location
    India
    Posts
    1,128

    Re: How to get 24 hours date time format in J2ME ?

    Quote Originally Posted by maaz4 View Post
    thanks for your help sir.

    but when I use

    " Date date = new Date(); "

    I am getting 12-hours format date. How can I get 24-hours format ? Does this depends on phone time format ?
    You can change your date format below mentioned ways:

    Date dt = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dt);
    StringBuffer temp = new StringBuffer();

    temp.append(calendar.get(Calendar.DAY_OF_MONTH));
    temp.append('.');
    temp.append(calendar.get(Calendar.MONTH) + 1);
    temp.append('.');
    temp.append(calendar.get(Calendar.YEAR));

    temp.append(' ');
    temp.append(calendar.get(Calendar.HOUR_OF_DAY));
    temp.append(':');
    temp.append(calendar.get(Calendar.MINUTE));
    temp.append(':');
    temp.append(calendar.get(Calendar.SECOND));

    return temp.toString();

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    11

    Re: How to get 24 hours date time format in J2ME ?

    Hi,

    Setting and getting date in java is usually done in milliseconds. After creating a calendar instance, you can use HOUR_OF_DAY field to get the time in 24 format.
    As per Java docs -
    HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.
    For example,
    Calendar cal = Calendar.getInstance();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    ...

    Again if you want to send the time over network, convert the time stamp into milli seconds and then send. getTimeInMillis() method of Calendar class will serve this purpose. I hope this will be helpful.

Similar Threads

  1. Replies: 0
    Last Post: 2010-10-11, 06:57
  2. Replies: 0
    Last Post: 2009-04-02, 07:49
  3. RFileLogger Date/Time Format
    By tsdgeos in forum Symbian
    Replies: 1
    Last Post: 2009-03-11, 04:59
  4. Date and Time format
    By deepu28 in forum Mobile Java General
    Replies: 5
    Last Post: 2008-01-25, 15:09
  5. Date and time format
    By jaazz in forum Mobile Java General
    Replies: 4
    Last Post: 2006-07-21, 19:48

Posting Permissions

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