Skip to content

Instantly share code, notes, and snippets.

@BenJam
Created November 28, 2010 16:16
Show Gist options
  • Save BenJam/719062 to your computer and use it in GitHub Desktop.
Save BenJam/719062 to your computer and use it in GitHub Desktop.
function to return iOS-like date's for lists etc.
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