justinooo

BetterSeal Expire Date - C#

Jun 21st, 2017
1,169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using BetterSeal;
  2.  
  3. public class Time
  4. {
  5.  
  6.     public static int epochTimeStamp(int year = 1970, int month = 1, int day = 1)
  7.     {
  8.         DateTime currentTime = DateTime.Now.ToUniversalTime;
  9.         DateTime epoch = new DateTime(year, month, day);
  10.         return (currentTime.Subtract(epoch)).TotalSeconds;
  11.     }
  12.  
  13.     public static string GetDaySuffix(int day)
  14.     {
  15.         switch (day) {
  16.             case 1:
  17.             case 21:
  18.             case 31:
  19.                 return "st";
  20.             case 2:
  21.             case 22:
  22.                 return "nd";
  23.             case 3:
  24.             case 23:
  25.                 return "rd";
  26.             default:
  27.                 return "th";
  28.         }
  29.     }
  30.  
  31.     public static string expireDate(LoginResponse userInfo)
  32.     {
  33.         if (userInfo.lifetime) return "Never";
  34.         int userEpoch = userInfo.remain;
  35.         int secondsLeft = userEpoch - epochTimeStamp();
  36.         DateTime expiredDateTime = Now.ToUniversalTime.AddSeconds(secondsLeft);
  37.         return expiredDateTime.ToString("MMMM d") + GetDaySuffix(expiredDateTime.Day) + ", " + expiredDateTime.ToString("yyyy");
  38.     }
  39.  
  40. }
RAW Paste Data