Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Library Example
Demonstration of Time library routines usage for time calculations in UNIX time format.
program Time_Demo
dim epoch, diff as longint
'***********************************
ts1, ts2 
as TimeStruct
'***********************************
main:
ts1.ss = 0
ts1.mn = 7
ts1.hh = 17
ts1.md = 23
ts1.mo = 5
ts1.yy = 2006
' *
' * What is the epoch of the date in ts ?
' *
epoch = Time_dateToEpoch(@ts1)           ' 1148404020
' *
' * What date is epoch 1234567890 ?
' *
epoch = 1234567890
Time_epochToDate(epoch, @ts2)            ' {0x1E, 0x1F, 0x17, 0x0D,
0x04, 0x02, 0x07D9)
' *
' * How much seconds between this two dates ?
' *
diff = Time_dateDiff(@ts1, @ts2)         ' 86163870
end.
TimeStruct type definition
structure TimeStruct
dim ss as byte  ' seconds
dim mn as byte
' minutes
dim hh as byte  ' hours
dim md as byte  ' day in month, from 1 to 31
dim wd as byte 
' day in week, monday=0, tuesday=1, .... sunday=6
dim mo  as byte 
' month number, from 1 to 12 (and not from 0
to 11 as with unix C time !)
dim yy as word
' year Y2K compliant, from 1892 to 2038
end structure
497
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6