[Gambas-user] Unix Date conversion

Stefano Palmeri stefanopalmeri at ...152...
Wed Jul 26 05:45:44 CEST 2006


Hi, all. 

It's just for fun... Same result as Laurent Carlier, but using 'date'.
Just another example of GNU/Linux and Gambas
magics...

PUBLIC SUB Main()

   PRINT ConvertFromUnix(1142123287)
     
END 

PUBLIC SUB ConvertFromUnix(lSeconds AS Long) AS String

  DIM lUnixDateNow AS Long
  DIM sDateOutput AS String
  DIM lDifference AS Long
    
  SHELL "`which date` +%s" TO sDateOutput  
        
  lUnixDateNow = Val(sDateOutput)
  lDifference = lUnixDateNow - lSeconds
  lDifference = lDifference * -1
   
  SHELL "`which date` '+%d/%m/%Y %H:%M:%S' --utc --date " &
        "'" & lDifference & " seconds'" TO sDateOutput
  
  RETURN Trim$(sDateOutput)
    
END


Regards,

Stefano Palmeri




More information about the User mailing list