justinooo icon

BetterSeal Expire Date - C#

justinooo | PRO | 06/21/17 09:45:12 PM UTC | 0 ⭐ | 1908 👁️ | Never ⏰ | []
C# |

920 B

|

None

|

0 👍

/

0 👎

using BetterSeal;
 
public class Time
{
 
    public static int epochTimeStamp(int year = 1970, int month = 1, int day = 1)
    {
        DateTime currentTime = DateTime.Now.ToUniversalTime;
        DateTime epoch = new DateTime(year, month, day);
        return (currentTime.Subtract(epoch)).TotalSeconds;
    }
 
    public static string GetDaySuffix(int day)
    {
        switch (day) {
            case 1:
            case 21:
            case 31:
                return "st";
            case 2:
            case 22:
                return "nd";
            case 3:
            case 23:
                return "rd";
            default:
                return "th";
        }
    }
 
    public static string expireDate(LoginResponse userInfo)
    {
        if (userInfo.lifetime) return "Never";
        int userEpoch = userInfo.remain;
        int secondsLeft = userEpoch - epochTimeStamp();
        DateTime expiredDateTime = Now.ToUniversalTime.AddSeconds(secondsLeft);
        return expiredDateTime.ToString("MMMM d") + GetDaySuffix(expiredDateTime.Day) + ", " + expiredDateTime.ToString("yyyy");
    }
 
}

Comments