object.unlockTime

Type Number
Revision Release 2024.3703
Keywords steam, steamworks, achievements, AchievementInfo, unlockTime
See also AchievementInfo
steamworks.*

Overview

Number indicating a local Unix time value (seconds since 1970) of when the achievement was unlocked.

This will be nil if the achievement has not yet been unlocked.

If unlocked, this time value can be converted to a human-readable date and time string by passing it to the os.date() function. This time value can also be compared with the current time value returned by the os.time() function.

Example

local steamworks = require( "plugin.steamworks" )

local achievementInfo = steamworks.getAchievementInfo( "achievementName" )

if ( achievementInfo and achievementInfo.unlocked ) then
    -- Print when the achievement was unlocked
    print( "Achievement unlocked on " .. os.date( "%c", achievementInfo.unlockTime ) )

    -- Print how many days ago the achievement was unlocked
    local secondsPerDay = 86400
    local daysAgo = ( os.time() - achievementInfo.unlockTime ) / secondsPerDay
    print( "Achievement unlocked " .. string.format( "%0.1f", daysAgo ) .. " days ago" )
end