Created
June 9, 2014 16:43
-
-
Save timmarinin/b003c60383ae5bb926fa to your computer and use it in GitHub Desktop.
time formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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