×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    11

    Can´t get time from datefield

    Hi,

    I can´t get time value from a datefield.

    The user change the value on the datefield, but the new value never set to the component.

    What I really want to do, is to save the new value (seting by the user) in a rms file.

    I have test about 3 examples, but they doesn´t work either.

    I use midp 1.0, Serie 60 (Nokia 3620)

    I try with this
    Date date = datefield.getDate();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    Can anyone help me ?

    Thanks

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    9
    Hi,

    You have to use DateField.DATE_TIME and not
    DateField.DATE type DateField:

    ...
    // Add new Date element
    dtDate = new DateField("Date:", DateField.DATE_TIME);
    dtDate.setDate(rec.getDate());
    append(dtDate);
    ..

    For RMS persistence use 8 bytes (I used big endian).

    From RMS to long:

    // Get long value from byte array
    public static long getTimeFromByteArray(byte[] arr)
    {
    long lTime = 0;
    long lByte, lWeight = 1;

    // Get the bytes multiplied by weight
    for(int i = 0 ; i < 8 ; i++)
    {
    lByte = (long)arr[i];
    if (lByte < 0)
    lByte += 256;
    lTime += lByte * lWeight;
    lWeight *= 256;
    }

    // Return value
    return lTime;
    }

    and from long date to RMS byte array:

    // Set date part
    long lTime = d.getTime();
    long lByte;
    for(i = 0 ; i < 8 ; i++)
    {
    lByte = lTime % 256;
    buffer[i] = (byte)lByte;
    lTime /= 256;
    }


    Regards,

    Zoltan

Posting Permissions

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