'How to use time.time() in Telgram bot?

I'm trying to use the time.time() method in my telegram bot code for when someone uses the command /afk but inserting time.time() alone returned a set of numbers which I assumed to be all the time elapsed since epoch which is in UTC, not EST. After messing with it and reading some other suggestions, I managed to have the time show properly. But it was not the result I hoped for.

What I want is when someone goes afk, that the bot can display the time that has passed since they've been away. 1h, 2m, 35s...

My code is the following:

def check_afk(update, context, user_id, fst_name, userc_id):
    if sql.is_afk(user_id):
        user = sql.check_afk_status(user_id)
        if int(userc_id) == int(user_id):
            return
        if not user.reason:
            res = "{} is busy right now.\nDon't tag them unless you really have to.\nLast seen: <code>{}</code> UTC".format(fst_name, datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
            update.effective_message.reply_text(res)```

Current result.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source