Click here to Skip to main content
15,352,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to convert API ‘expires_in’ time of bearer token getting wrong result.
Please look at the code what I tried and please help me to get correct result

I am using visual studio 2015 and MVC4 .

What I have tried:

public DateTime UnixTimeStampToDateTime(double unixTimeStamp)
           System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
           dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
           return dtDateTime;

Input :

Output :
Expires in: 3/31/1970 11:59:59
Updated 7-Sep-21 21:58pm

1 solution

The expires_in value represents the number of seconds until the token expires. You need to add that to the current date/time, not to the Unix timestamp base date.

DateTimeOffset expiresAbsolute = DateTimeOffset.UtcNow.AddSeconds(7775999);
// 2021-12-07T07:58:09.4856895+00:00
saifulhaque 8-Sep-21 6:15am
It is working fine.Thank you so much...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900