Human readable timestamp – ShiVa Engine

Human readable timestamp

Here is a function that returns a nice human readable date/time string. Use like log.message(this.GetTimeStamp()) -by fraser

--------------------------------------------------------------------------------
--  Function......... : GetTimeStamp
--  Author........... :
--  Description...... :
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function AI_XXX.GetTimeStamp ( )
--------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------
    --  TIME
    local nTim = system.getTimeOfDay ( )
    local nHou = math.trunc ( math.mod ( nTim/3600, 24 ), 0 )
    local nMin = math.trunc ( math.mod ( nTim/60  , 60 ), 0 )
    local nSec = math.trunc ( math.mod ( nTim     , 60 ), 0 )
    local sTim = string.format ( "%02d:%02d:%02d", nHou, nMin, nSec )
    --------------------------------------------------------------------------------------------
    --  DAY
    local tsDay = table.newInstance ( )
    table.add ( tsDay, "Sun" )
    table.add ( tsDay, "Mon" )
    table.add ( tsDay, "Tue" )
    table.add ( tsDay, "Wed" )
    table.add ( tsDay, "Thu" )
    table.add ( tsDay, "Fri" )
    table.add ( tsDay, "Sat" )
    local sDay = table.getAt ( tsDay, system.getDayOfWeek ( ) )
    --------------------------------------------------------------------------------------------
    --  DATE
    local nDat = system.getDayOfMonth ( )
    local sDat
    local nUni = math.mod ( nDat, 10 )
    if(nUni == 1)
    then
        sDat = nDat.."st"
    elseif(nUni == 2)
    then
        sDat = nDat.."nd"
    elseif(nUni == 3)
    then
        sDat = nDat.."rd"
    else
        sDat = nDat.."th"
    end
    --------------------------------------------------------------------------------------------
    --  MONTH
    local tsMth = table.newInstance ( )
    table.add ( tsMth, "Jan" )
    table.add ( tsMth, "Feb" )
    table.add ( tsMth, "Mar" )
    table.add ( tsMth, "Apr" )
    table.add ( tsMth, "May" )
    table.add ( tsMth, "Jun" )
    table.add ( tsMth, "Jul" )
    table.add ( tsMth, "Aug" )
    table.add ( tsMth, "Sep" )
    table.add ( tsMth, "Oct" )
    table.add ( tsMth, "Nov" )
    table.add ( tsMth, "Dec" )
    local sMth = table.getAt ( tsMth, system.getMonth ( ) )
    --------------------------------------------------------------------------------------------
    --  YEAR
    local sYea = string.format ( "%d", system.getYear ( ) )
    --------------------------------------------------------------------------------------------
    --  RETURN ALL
    return sTim .. " " .. sDay .. " " .. sDat .. " " .. sMth .. " " .. sYea
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner