Created
November 28, 2010 16:16
-
-
Save BenJam/719062 to your computer and use it in GitHub Desktop.
function to return iOS-like date's for lists etc.
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
function dateMe(date){ | |
var now = new Date(); | |
var d = new Date(date); | |
if(now.getDay()==d.getDay() && now.getMonth()==d.getMonth() && now.getFullYear()==d.getFullYear()){ | |
return d.toTimeString().match(/\d+:\d+/); | |
}else if(now.getDay()==d.getDay()+1 && now.getMonth()==d.getMonth() && now.getFullYear()==d.getFullYear()){ | |
return 'Yesterday'; | |
}else{ | |
return d.toLocaleDateString().match(/\d+\s\D{3}/); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment