JQuery – Converts minutes into days, week, months and years
<script>
$(function() {
MINS_PER_YEAR = 24 * 365 * 60;
MINS_PER_MONTH = 24 * 30 * 60;
MINS_PER_WEEK = 24 * 7 * 60;
MINS_PER_DAY = 24 * 60;
MINS_PER_HOUR = 60;
$(“.minutes”).each(function() {
minutes = $(this).text();
minutes = parseInt(minutes);
years = Math.floor(minutes / MINS_PER_YEAR);
minutes = minutes – (years * MINS_PER_YEAR);
months = Math.floor(minutes / MINS_PER_MONTH);
minutes = minutes – (months * MINS_PER_MONTH);
weeks = Math.floor(minutes / MINS_PER_WEEK);
minutes = minutes – (weeks * MINS_PER_WEEK);
days = Math.floor(minutes / MINS_PER_DAY);
minutes = minutes – (days * MINS_PER_DAY);
hours = Math.floor(minutes / MINS_PER_HOUR);
minutes = minutes – (hours * MINS_PER_HOUR);
if(years){current_years_part = years +’ year(s) ‘; }else{ current_years_part = ”; }
if(months){current_months_part = months +’ month ‘; }else{ current_months_part = ”; }
if(weeks){current_weeks_part = weeks +’ week ‘; }else{ current_weeks_part = ”; }
if(days){current_days_part = days +’ day ‘; }else{ current_days_part = ”; }
if(hours){current_hours_part = hours +’ hour ‘; }else{ current_days_part = ”; }
$(this).text(current_years_part +’ ‘+current_months_part +’ ‘+current_weeks_part +’ ‘+current_days_part +’ ‘+current_hours_part +’ ‘+minutes+ ‘ minutes’ );
});
});
</script>
<body>
<span class=’minutes’>654321</span>
<span class=’minutes’>341834321</span>
<span class=’minutes’>5452334321</span>
</body>
similar source: http://stackoverflow.com/questions/7812742/converts-minutes-into-days-week-months-and-years