Android Open Source - MyTwitter-Android Pretty Date Util






From Project

Back to project page MyTwitter-Android.

License

The source code is released under:

Apache License

If you think the Android project MyTwitter-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.fukata.android.mytw.util;
/*w  w w. j  a  v  a  2 s .  com*/
import java.util.Date;

public enum PrettyDateUtil {
  ;

  public static String toString(Date date) {
    long  current = (new Date()).getTime(),
      timestamp = date.getTime(),
      diff = (current - timestamp)/1000;
    int  amount = 0;
    String  what = "";

    /**
     * Second counts
     * 3600: hour
     * 86400: day
     * 604800: week
     * 2592000: month
     * 31536000: year
     */

    if(diff > 31536000) {
      amount = (int)(diff/31536000);
      what = "year";
    }
    else if(diff > 31536000) {
      amount = (int)(diff/31536000);
      what = "month";
    }
    else if(diff > 604800) {
      amount = (int)(diff/604800);
      what = "week";
    }
    else if(diff > 86400) {
      amount = (int)(diff/86400);
      what = "day";
    }
    else if(diff > 3600) {
      amount = (int)(diff/3600);
      what = "hour";
    }
    else if(diff > 60) {
      amount = (int)(diff/60);
      what = "minute";
    }
    else {
      amount = (int)diff;
      what = "second";
      if(amount < 6) {
        return "Just now";
      }
    }

    if(amount == 1) {
      if(what.equals("day")) {
        return "Yesterday";
      }
      else if(what.equals("week") || what.equals("month") || what.equals("year")) {
        return "Last " + what;
      }
    }
    else {
      what += "s";
    }

    return amount + " " + what + " ago";
  }
}




Java Source Code List

org.fukata.android.mytw.DirectMessageTimelineAdapter.java
org.fukata.android.mytw.DirectMessageTimelineView.java
org.fukata.android.mytw.HomeTimelineView.java
org.fukata.android.mytw.MentionTimelineView.java
org.fukata.android.mytw.MyTwitterActivity.java
org.fukata.android.mytw.MyTwitterApp.java
org.fukata.android.mytw.SettingsActivity.java
org.fukata.android.mytw.TimelineActivity.java
org.fukata.android.mytw.TimelineAdapter.java
org.fukata.android.mytw.TimelineItem.java
org.fukata.android.mytw.TimelineView.java
org.fukata.android.mytw.UpdateStatusActivity.java
org.fukata.android.mytw.database.MyTwitterDB.java
org.fukata.android.mytw.database.dao.BaseDao.java
org.fukata.android.mytw.database.dao.TweetDao.java
org.fukata.android.mytw.database.dto.TweetDto.java
org.fukata.android.mytw.database.schema.TweetSchema.java
org.fukata.android.mytw.receiver.InstallAnalyticsReceiver.java
org.fukata.android.mytw.twitter.Twitter.java
org.fukata.android.mytw.twitter.rs.Status.java
org.fukata.android.mytw.twitter.rs.User.java
org.fukata.android.mytw.util.PrettyDateUtil.java
org.fukata.android.mytw.util.SettingUtil.java
org.fukata.android.mytw.util.StringMatchUtils.java
org.fukata.android.mytw.util.StringUtils.java