Jumping Jack Flash weblog

Date format in Symbian phones

Posted in Symbian by jumpjack on 16 febbraio 2007

Symbian devices stores time/date information using an integer which represents microseconds elapsed since 1/jan/0000 in Gregorian Calendar.

Example:

‘[] (16’00e0d8c8757752c0)/1000000 = [2005-07-16 16:24:19] 
 

This line is coded in “AddUp” language: AddUp is a freeware calculator which allows doing complex calculations with very large numbers, and doing conversions between number formats.

‘[]  means “convert to Gregorian Date the following number

16′ means “following number is represented in base-16”

[2005-07-16 16:24:19   Square brackets include a date in format yyyy-mm-dd hh:mm:ss

So, date ‘ 2005-07-16 16:24:19‘ will be represented by sequence “00e0d8c8757752c0”, i. e. 00 e0 d8 c8 75 77 52 c0 , which is stored in reverse order, i.e.  c0 52 77 75 c8 d8 e0 00 .

To convert an hexadecimal sequence to a Gregorian date:

– write the 8 bytes sequence in reverse order; for example:
00E112D7F85CD680 (always begins with 00e1 or 00e0)

– write it into Windows calculator (in hexadecimal mode)

– switch to decimal mode: you’ll obtain number of milliseconds since 1/jan/0001 00:00 :
63352588554000000

– Divide by 1000000 to obtain seconds
63352588554

– Subtract 1 year and 11 days (year 0000 an d day 0 do not exists in Gregorian calendar, and 101 days were “deleted” in Gregorian calendar); to do this, subtract 32486400:
63320102154

– Divide by 86400 to obtain days:
732871,55270833333333333333333333

– Add fix number 1721423.5 (days between start of Julian calendar and start of Gregorian calendar):
2454295,0527083333333333333333333

– Put this number in a Julian->Gregorian converter like this one (be sure to use proper decimal separator, depending on your country: “.” or “,”? )
In this particular case, you’ll get 2007/07/13 13:15:53
 

RapidQ/VisualBasic source to make the conversions (require this RapidQ source also list at the end of this page):

function microdate(s as string) as string
   DefInt y,m,d,intdays,intmin,inthours
   DefLng dd,lngdays
   DefDbl dbldays,decimals,hours,minutes
   s = mid$(s,5,6)
   intdays = val(convbase$(s,16,10))
   dbldays= (intdays* 16^6 / 1000000) /86400 + 729749.93962022 – 12 ‘ Gregorian correction (not included in TimeSerial???)
   lngdays = int(dbldays)
‘   print “stringa ricevuta: “,s,” – giorni equivalenti: “,intdays,”-“,dbldays,”-“,lngdays
   dd = datefromserial(lngdays,y,m,d)
   y=y-1 ‘ TimeSerial starts counting from AD 1, Symbian starts from AD 0.
   decimals = dbldays-lngdays
   hours = decimals*86400/3600
   minutes = int((hours – int(hours))*60)
   inthours = int(hours)
   intmin= int(minutes)
   microdate = lead0$(y) & “/” & lead0$(m) & “/” & lead0$(d) & ” – ” & lead0$(inthours) & “:” & lead0$(intmin) & “; ”
end function

The TimeFromSerial source:

FUNCTION DateFromSerial(dateSerial AS LONG, ByRef Year AS LONG, ByRef Month AS LONG, ByRef Day AS LONG) AS LONG
   ‘ declare
      DEFLNG daysCount, dayOfMonth, dayTotal
   ‘ initialize
      Year = 1
      Month = 1
      daysCount = dateSerial – 1
   ‘ pre-process
      IF daysCount > 146096 THEN
       Year = Year + (daysCount \ 146097) * 400
       daysCount = (daysCount MOD 146097)
      END IF
      IF daysCount > 36523 THEN
       dayTotal = (daysCount \ 36524)
       IF dayTotal < 4 THEN
        Year = Year + (dayTotal * 100)
        daysCount = (daysCount MOD 36524)
       ELSE
        Year = Year + 300
        daysCount = 36524
       END IF
      END IF
      IF daysCount > 1460 THEN
       Year = Year + (daysCount \ 1461) * 4
       daysCount = (daysCount MOD 1461)
      END IF
      IF daysCount > 364 THEN
       dayTotal = (daysCount \ 365)
       IF dayTotal < 4 THEN
        Year = Year + dayTotal
        daysCount = (daysCount MOD 365)
       ELSE
        Year = Year + 3
        daysCount = 365
       END IF
      END IF
   ‘ process
      Day = daysCount + 1
      dayOfMonth = &H3DFF7F9F
      IF Day > 58 AND isLeapYear(Year) THEN dayOfMonth = (dayOfMonth + 32)
      DO
       dayTotal = (dayOfMonth AND 31)
       IF dayTotal >= Day THEN EXIT DO
       Day = Day – dayTotal
       Month = Month + 1
       dayOfMonth = (dayOfMonth \ 32)
       IF dayOfMonth = 0 THEN dayOfMonth = &H3FEFFBFF
      LOOP
   ‘ exit
      Result = (dateSerial MOD 7)
     END FUNCTION

2 Risposte

Subscribe to comments with RSS.

  1. One said, on 3 aprile 2011 at 15:27

    Thankss a lot

  2. […] Date format in Symbian phones […]


Puoi inserire un commento qui sotto; diventerà visibile dopo la moderazione dell'amministratore

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: