#Get UTC Time from Unix TimeSpan

12 messages · Page 1 of 1 (latest)

sullen abyss
#

i have an api that created with C#. that api use jwt for auth.. inside jwt has a property called exp that contain Unix TImeSpan of expire date in UTC Format. so now how to get current date-time as utc format and compare it to expire date?

TL;DR : i want current time as Unix TimeSpan UTC and Compare it with my own Unix TimeSpan UTC.

craggy lodgeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

prime tendon
#
let utc_timestamp = new Date().getTime();
if (utc_timestamp>=(jwt_exp_time*1000)){
console.log("token expired")
}
sullen abyss
#

thanks but as i know that code return time from system time zone not UTC.

prime tendon
#

iirc it adjust it after conversion, so inside unixtime it's seconds from UTC.

sullen abyss
#

thanks. i will check it if it's work.

#

no it's not. it's timespan of that timezone.

#

i think this is what i want,

    const utc = new Intl.DateTimeFormat('en-GB', {
        year: "numeric",
        month: "numeric",
        day: "numeric",
        hour: "numeric",
        minute: "numeric",
        second: "numeric",
        hour12: false,
        timeZone: 'UTC',
    }).format(new Date());

then

const utcNow = new Date(utc).getTime();
//then compar utcNow with my own timezone. i just have to check it to see it's work or not.
#

if any one has better solution feel free to help me.

prime tendon
#

maybe this

Date.parse(new Date().toISOString())
sullen abyss
#

thanks. yes that is what i want.

#

and work as expected.