How to turn Date() method into a Discord hover able timestamp


I am making a Discord bot on and I was trying to convert a Date() function into a Discord hover able timestamp.

I know there are websites that can convert it, but I want to be able to convert it in my code because each timestamp will be different.

This is what I mean by the Discord timestamp.
Screenshot 2022-04-20 155451

This is my code:

var user = await Levels.fetch(mentionedMember, interaction.guildId, true);
    var lastUpdatedDate = new Date(user.lastUpdated).toLocaleDateString("en-US");
    var lastUpdatedTime = new Date(user.lastUpdated).toLocaleTimeString("en-US");
    return `<@${user.userID}> is **level ${user.level}** with **${user.xp} xp**. Last updated on ${lastUpdatedDate} at ${lastUpdatedTime} *(PST)*.`

The output is this:

The main reason I want to turn this into a Discord timestamp is so it will automatically adjust to the user’s time zone.

Thank you!

1 Like

Nevermind, I solved the problem myself.

But I’ll say the answer to help other people.

I converted the Date() into a unixtimestamp by using this line of code:

const unixTimestamp = Math.floor(lastUpdatedTime.getTime() / 1000);

Then I could use it as a Discord timestamp by using this:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.