Get UTC Time from Unix TimeSpan
Unanswered
Banjara Hound posted this in #help-forum
Banjara HoundOP
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.
TL;DR : i want current time as Unix TimeSpan UTC and Compare it with my own Unix TimeSpan UTC.
11 Replies
Toyger
let utc_timestamp = new Date().getTime();
if (utc_timestamp>=(jwt_exp_time*1000)){
console.log("token expired")
}Banjara HoundOP
thanks but as i know that code return time from system time zone not UTC.
Toyger
iirc it adjust it after conversion, so inside unixtime it's seconds from UTC.
Banjara HoundOP
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,
then
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.
Toyger
maybe this
Date.parse(new Date().toISOString())Banjara HoundOP
thanks. yes that is what i want.
Banjara HoundOP
and work as expected.
js should create a method that get utc time from timezone server not client or server of poject