List of usage examples for android.text.format DateUtils SECOND_IN_MILLIS
long SECOND_IN_MILLIS
To view the source code for android.text.format DateUtils SECOND_IN_MILLIS.
Click Source Link
From source file:Main.java
/** * This method make ANR/* w ww.ja v a 2 s . c om*/ */ public static void anr() { // for (int i = 1, n = 0; i > n; i++) { // Log.d(TAG, "i=" + i + ", n=" + n); // } try { Thread.sleep(DateUtils.SECOND_IN_MILLIS * 12); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Main.java
public static String igFormattedDate(String timestamp) { /**/* ww w . j a v a2 s. com*/ * From the group discussion board. */ CharSequence relativeDateTimeString = DateUtils.getRelativeTimeSpanString(Long.parseLong(timestamp) * 1000, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS); return relativeDateTimeString.toString().replaceAll("[^0-9]+", "s"); }
From source file:Main.java
public static String getRelativeTimeAgo(String rawJsonDate) { String twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat sf = new SimpleDateFormat(twitterFormat, Locale.ENGLISH); sf.setLenient(true);/*from ww w.j a va 2 s . c o m*/ String relativeDate = ""; try { long dateMillis = sf.parse(rawJsonDate).getTime(); relativeDate = DateUtils .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS) .toString(); } catch (ParseException e) { e.printStackTrace(); } // Shorten relative date relativeDate = relativeDate.replaceAll(" ", "").replace("seconds", "s").replace("second", "s") .replace("minutes", "m").replace("minute", "m").replace("hours", "h").replace("hour", "h") .replace("days", "d").replace("day", "d").replace("weeks", "w").replace("week", "w") .replace("months", "M").replace("month", "M").replace("years", "y").replace("year", "y") .replace("ago", "").replace("in", "").replace("0s", "just now"); return relativeDate; }
From source file:Main.java
public static String getTimeString(Date fromdate) { long then;//from ww w . j a va 2s. c o m then = fromdate.getTime(); Date date = new Date(then); StringBuffer dateStr = new StringBuffer(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar now = Calendar.getInstance(); int days = daysBetween(calendar.getTime(), now.getTime()); int minutes = hoursBetween(calendar.getTime(), now.getTime()); int hours = minutes / 60; if (days == 0) { int second = minuteBetween(calendar.getTime(), now.getTime()); if (minutes > 60) { if (hours >= 1 && hours <= 24) { dateStr.append(hours).append("h"); } } else { if (second <= 10) { dateStr.append("Now"); } else if (second > 10 && second <= 30) { dateStr.append("few seconds ago"); } else if (second > 30 && second <= 60) { dateStr.append(second).append("s"); } else if (second >= 60 && minutes <= 60) { dateStr.append(minutes).append("m"); } } } else if (hours > 24 && days <= 7) { dateStr.append(days).append("d"); } else { dateStr.append(DateUtils.getRelativeTimeSpanString(date.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)); } return dateStr.toString(); }
From source file:Main.java
public static int minuteBetween(Date d1, Date d2) { return (int) ((d2.getTime() - d1.getTime()) / DateUtils.SECOND_IN_MILLIS); }
From source file:com.alchemiasoft.book.receiver.SuggestionReceiver.java
/** * Schedule a suggestion alarm.// w w w. jav a2 s .co m * * @param context reference. * @return true if the alarm has been successfully scheduled, false otherwise. */ public static boolean scheduleSuggestion(Context context) { final AlarmManager alarmManager = AlarmUtil.getAlarmManager(context); if (sPendingIntent != null) { alarmManager.cancel(sPendingIntent); } final UserData userData = UserData.load(context); final UserData.SuggestionInterval interval = userData.suggestionInterval(); if (interval == UserData.SuggestionInterval.NEVER) { return false; } final Intent intent = new Intent(SUGGESTION_ACTION); sPendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); final long refreshInMills = interval.seconds() * DateUtils.SECOND_IN_MILLIS; Log.d(TAG_LOG, "AlarmReceiver: scheduling suggestion in " + interval.seconds() + " sec(s)."); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + refreshInMills, sPendingIntent); return true; }
From source file:net.simonvt.cathode.ui.fragment.MovieWatchlistFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { SimpleCursorLoader loader = new SimpleCursorLoader(getActivity(), Movies.MOVIES, null, MovieColumns.IN_WATCHLIST + "=1 AND " + MovieColumns.NEEDS_SYNC + "=0", null, Movies.DEFAULT_SORT); loader.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return loader; }
From source file:net.simonvt.cathode.ui.fragment.MovieCollectionFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { SimpleCursorLoader loader = new SimpleCursorLoader(getActivity(), Movies.MOVIES, null, MovieColumns.IN_COLLECTION + "=1 AND " + MovieColumns.NEEDS_SYNC + "=0", null, Movies.DEFAULT_SORT); loader.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return loader; }
From source file:net.simonvt.cathode.ui.fragment.ShowsCollectionFragment.java
@Override public Loader<SimpleCursor> onCreateLoader(int i, Bundle bundle) { final Uri contentUri = Shows.SHOWS_COLLECTION; SimpleCursorLoader cl = new SimpleCursorLoader(getActivity(), contentUri, ShowsWithNextAdapter.PROJECTION, null, null, Shows.DEFAULT_SORT); cl.setUpdateThrottle(2 * DateUtils.SECOND_IN_MILLIS); return cl;// w w w .ja v a2 s . c om }
From source file:net.niyonkuru.koodroid.ui.TabDetailFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { CursorLoader loader = new CursorLoader(mContext, Tabs.buildTransactionsUri(getSubscriber()), TabTransactionsQuery.PROJECTION, null, null, TabTransactions.DEFAULT_SORT); loader.setUpdateThrottle(DateUtils.SECOND_IN_MILLIS); return loader; }