title: How do I convert seconds since Epoch to current date and time?
body: <p>I know I posted this a while ago, but I figured out the solution. I wrote this code for a game called Roblox, but I'm just posting the code here in case anyone else who has this same problem needs a solution. Anyways, here's the code:</p>
  
  <pre><code>outputTime = true -- true: will print the current time to output window. false: won't print time
  createVariable = true -- true: creates variables under game.Lighting. false: won't create variables
  
  -----------------------------------------------------------------------------------------------
  --DO NOT EDIT BELOW----------------------------------------------------------------------------
  -----------------------------------------------------------------------------------------------
  
  if(createVariable) then
      yearVar = Instance.new("IntValue", game.Lighting)
      yearVar.Name = "Year"
      yearVar.Value = 0
      monthVar = Instance.new("IntValue", game.Lighting)
      monthVar.Name = "Month"
      monthVar.Value = 0
      dayVar = Instance.new("IntValue", game.Lighting)
      dayVar.Name = "Day"
      dayVar.Value = 0
      hourVar = Instance.new("IntValue", game.Lighting)
      hourVar.Name = "Hour"
      hourVar.Value = 0
      minuteVar = Instance.new("IntValue", game.Lighting)
      minuteVar.Name = "Minute"
      minuteVar.Value = 0
      secondVar = Instance.new("IntValue", game.Lighting)
      secondVar.Name = "Second"
      secondVar.Value = 0
      dayOfWeek = Instance.new("StringValue", game.Lighting)
      dayOfWeek.Name = "DayOfWeek"
      dayOfWeek.Value = "Thursday"
  end
  function giveZero(data)
      if string.len(data) &lt;= 1 then
          return "0" .. data
      else
          return data
      end
  end
  function hasDecimal(value)
      if not(value == math.floor(value)) then
          return true
      else
          return false
      end
  end
  function isLeapYear(year)
      if(not hasDecimal(year / 4)) then
          if(hasDecimal(year / 100)) then
              return true
          else
              if(not hasDecimal(year / 400)) then
                  return true
              else
                  return false
              end
          end
      else
          return false
      end
  end
  local eYear = 1970
  local timeStampDayOfWeak = 5
  local secondsInHour = 3600
  local secondsInDay = 86400
  local secondsInYear = 31536000
  local secondsInLeapYear = 31622400
  local monthWith28 = 2419200
  local monthWith29 = 2505600
  local monthWith30 = 2592000
  local monthWith31 = 2678400
  local monthsWith30 = {4, 6, 9, 11}
  local monthsWith31 = {1, 3, 5, 7, 8, 10, 12}
  local daysSinceEpoch = 0
  local DOWAssociates = {"Tursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"}
  while(true) do
      now = tick()
      year = 1970
      secs = 0
      daysSinceEpoch = 0
      while((secs + secondsInLeapYear) &lt; now or (secs + secondsInYear) &lt; now) do
          if(isLeapYear(year+1)) then
              if((secs + secondsInLeapYear) &lt; now) then
                  secs = secs + secondsInLeapYear
                  year = year + 1
                  daysSinceEpoch = daysSinceEpoch + 366
              end
          else
              if((secs + secondsInYear) &lt; now) then
                  secs = secs + secondsInYear
                  year = year + 1
                  daysSinceEpoch = daysSinceEpoch + 365
              end
          end
      end
      secondsRemaining = now - secs
      monthSecs = 0
      yearIsLeapYear = isLeapYear(year)
      month = 1 -- January
      while((monthSecs + monthWith28) &lt; secondsRemaining or (monthSecs + monthWith30) &lt; secondsRemaining or (monthSecs + monthWith31) &lt; secondsRemaining) do
          if(month == 1) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 2
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 2) then
              if(not yearIsLeapYear) then
                  if((monthSecs + monthWith28) &lt; secondsRemaining) then
                      month = 3
                      monthSecs = monthSecs + monthWith28
                      daysSinceEpoch = daysSinceEpoch + 28
                  else
                      break
                  end
              else
                  if((monthSecs + monthWith29) &lt; secondsRemaining) then
                      month = 3
                      monthSecs = monthSecs + monthWith29
                      daysSinceEpoch = daysSinceEpoch + 29
                  else
                      break
                  end
              end
          end
          if(month == 3) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 4
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 4) then
              if((monthSecs + monthWith30) &lt; secondsRemaining) then
                  month = 5
                  monthSecs = monthSecs + monthWith30
                  daysSinceEpoch = daysSinceEpoch + 30
              else
                  break           
              end
          end
          if(month == 5) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 6
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 6) then
              if((monthSecs + monthWith30) &lt; secondsRemaining) then
                  month = 7
                  monthSecs = monthSecs + monthWith30
                  daysSinceEpoch = daysSinceEpoch + 30
              else
                  break
              end
          end
          if(month == 7) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 8
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 8) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 9
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 9) then
              if((monthSecs + monthWith30) &lt; secondsRemaining) then
                  month = 10
                  monthSecs = monthSecs + monthWith30
                  daysSinceEpoch = daysSinceEpoch + 30
              else
                  break
              end
          end
          if(month == 10) then
              if((monthSecs + monthWith31) &lt; secondsRemaining) then
                  month = 11
                  monthSecs = monthSecs + monthWith31
                  daysSinceEpoch = daysSinceEpoch + 31
              else
                  break
              end
          end
          if(month == 11) then
              if((monthSecs + monthWith30) &lt; secondsRemaining) then
                  month = 12
                  monthSecs = monthSecs + monthWith30
                  daysSinceEpoch = daysSinceEpoch + 30
              else
                  break
              end
          end
      end
      day = 1 -- 1st
      daySecs = 0
      daySecsRemaining = secondsRemaining - monthSecs
      while((daySecs + secondsInDay) &lt; daySecsRemaining) do
          day = day + 1
          daySecs = daySecs + secondsInDay
          daysSinceEpoch = daysSinceEpoch + 1
      end
      hour = 0 -- Midnight
      hourSecs = 0
      hourSecsRemaining = daySecsRemaining - daySecs
      while((hourSecs + secondsInHour) &lt; hourSecsRemaining) do
          hour = hour + 1
          hourSecs = hourSecs + secondsInHour
      end
      minute = 0 -- Midnight
      minuteSecs = 0
      minuteSecsRemaining = hourSecsRemaining - hourSecs
      while((minuteSecs + 60) &lt; minuteSecsRemaining) do
          minute = minute + 1
          minuteSecs = minuteSecs + 60
      end
      second = math.floor(now % 60)
      year = giveZero(year)
      month = giveZero(month)
      day = giveZero(day)
      hour = giveZero(hour)
      minute = giveZero(minute)
      second = giveZero(second)
      remanderForDOW = daysSinceEpoch % 7
      DOW = DOWAssociates[remanderForDOW + 1]
      if(createVariable) then
          yearVar.Value = year
          monthVar.Value = month
          dayVar.Value = day
          hourVar.Value = hour
          minuteVar.Value = minute
          secondVar.Value = second
          dayOfWeek.Value = DOW
      end
      if(outputTime) then
          str = "Year: " .. year .. ", Month: " .. month .. ", Day: " .. day .. ", Hour: " .. hour .. ", Minute: " .. minute .. ", Second: ".. second .. ", Day of Week: " .. DOW
          print(str)
      end
      wait(1)
  end
  </code></pre>
  
  <p>----ORIGINAL POST----
  What are the formulas for calculating the following given no resources except the seconds since Epoch?</p>
  
  <p>Here's a list of what I need:</p>
  
  <blockquote>
    <p>Current Month of year Ex: 7</p>
    
    <p>Current day of month Ex: 25</p>
    
    <p>Current day of week Ex: Thursday (1-7 would be acceptable)</p>
    
    <p>Current hour of day Ex: 22</p>
    
    <p>Current minute of hour Ex: 34</p>
    
    <p>Current second of minute: 07</p>
  </blockquote>