Skip to content

Instantly share code, notes, and snippets.

@timmarinin
Created June 9, 2014 16:43
Show Gist options
  • Save timmarinin/b003c60383ae5bb926fa to your computer and use it in GitHub Desktop.
Save timmarinin/b003c60383ae5bb926fa to your computer and use it in GitHub Desktop.
time formatting
var created = new Date(opinion.created), timeFormatted, distance = ~~((new Date() - created) / 86400000);
var hours = created.getHours().toString().length === 1 ? '0' + created.getHours() : created.getHours();
var minutes = created.getMinutes().toString().length === 1 ? '0' + created.getMinutes() : created.getMinutes();
timeFormatted = hours + ':' + minutes;
switch(distance) {
case 0:
break;
case 1:
timeFormatted = "вчера в " + timeFormatted;
break;
case 2:
timeFormatted = "позавчера в " + timeFormatted;
break;
default:
timeFormatted = distance + ' ' + fsLang.plural(distance, ["дней", "день", "дня", "дней"]) + " назад";
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment