Created
December 1, 2016 09:33
-
-
Save akamahesh/3d6b6532c672a57436dd038a55e93cdd to your computer and use it in GitHub Desktop.
RecentTime 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
//TODO need to change | |
String recentTime="2016-11-18 08:48:34"; | |
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy | |
Date now = new Date(); | |
String currentTime = sdfDate.format(now); | |
try { | |
Date d1 = sdfDate.parse(recentTime); | |
Date d2 = sdfDate.parse(currentTime); | |
long dl1=d1.getTime(); | |
long dl2=d2.getTime(); | |
long diff=dl2-dl1; | |
int secs= (int) (diff/1000); | |
if (secs<60){ | |
Date rightnow=new Date(); | |
SimpleDateFormat sd = new SimpleDateFormat("HH:mm"); | |
String rightnowTime=sd.format(rightnow); | |
holder.mTextViewRecentActivity.setText(rightnowTime); | |
}else if(secs<3600&& secs>60) { | |
secs=secs/60; | |
holder.mTextViewRecentActivity.setText(secs+" mins"); | |
}else if(secs>3600&&secs<86400){ | |
holder.mTextViewRecentActivity.setText(convert(diff)); | |
}else{ | |
int days=secs/86400; | |
if(days<2){ | |
holder.mTextViewRecentActivity.setText(days+" days ago"); | |
}else { | |
holder.mTextViewRecentActivity.setText(days+" days ago"); | |
} | |
} | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment