[Gambas-user] Unix Date conversion
Laurent Carlier
lordheavym at ...626...
Mon Jul 24 16:56:57 CEST 2006
Le lundi 24 juillet 2006 06:13, sbungay a écrit :
> I've been coding for the last 17 hours and can no longer see straight
> let alone think straight... :)
> Have a Unix date stored in a table and need to convert it to
> something the average human can read... there should be a function for
> this... and at the moment I am too tired to write one.. anybody got one
> they can part with? I've been looking through the gambas docs and don't
> see anything there (although I'm so tired I could walk right past the
> answer and not see it).
>
> Steve....ZZZzzzzzzz...
>
> Good night all (to those in Europe... good morning!)
>
Try this, i just going to do it
It's really dirty but it should work
' Gambas module file
PUBLIC SUB Main()
PRINT convert(1142123287)
END
PUBLIC FUNCTION convert(value AS Integer) AS Date
DIM $valYear AS Integer
DIM $valMonth AS Integer = 1
DIM $valDay AS Integer
DIM $valHour AS Integer
DIM $valMinute AS Integer
DIM $valSecond AS Integer
DIM $Months AS Integer[] = [31, 27, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
DIM $i AS Integer
DIM $valTmp AS Float
$valTmp = (value / (365.25 * 60 * 60 * 24))
$valYear = 1970 + $valTmp
IF (checkYear($valYear)) THEN INC ($Months[1])
$valTmp = Frac($valTmp) * 365.25
FOR EACH $i IN $Months
IF $valTmp > $i THEN
$valTmp = $valTmp - $i
INC ($valMonth)
ELSE
BREAK
ENDIF
NEXT
$valDay = $valTmp
$valTmp = ($valTmp - $valDay) * 24
$valHour = $valTmp
$valTmp = ($valTmp - $valHour) * 60
$valMinute = $valTmp
$valTmp = ($valTmp - $valMinute) * 60
$valSecond = $valTmp
RETURN Date($valYear, $valMonth, $valDay, $valHour, $valMinute, $valSecond)
END
PUBLIC FUNCTION checkYear(value AS Integer) AS Boolean
IF ((((value MOD 4) = 0) AND (value MOD 100) <> 0) OR ((value MOD 400) = 0))
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
END
--
Regards,
More information about the User
mailing list