List of usage examples for android.text.format Time setToNow
public void setToNow()
From source file:com.example.android.sunshine.app.Utility.java
/** * Converts db date format to the format "Month day", e.g "June 24". * @param context Context to use for resource localization * @param dateInMillis The db formatted date string, expected to be of the form specified * in Utility.DATE_FORMAT * @return The day in the form of a string formatted "December 6" *///w ww. jav a2 s. c o m public static String getFormattedMonthDay(Context context, long dateInMillis) { Time time = new Time(); time.setToNow(); SimpleDateFormat dbDateFormat = new SimpleDateFormat(Utility.DATE_FORMAT); SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd"); String monthDayString = monthDayFormat.format(dateInMillis); return monthDayString; }
From source file:com.example.android.sunshine.app.Utility.java
/** * Given a day, returns just the name to use for that day. * E.g "today", "tomorrow", "wednesday". * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return/*from w w w .j av a 2 s. c om*/ */ public static String getDayName(Context context, long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name. Time t = new Time(); t.setToNow(); int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff); int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff); if (julianDay == currentJulianDay) { return context.getString(R.string.today); } else if (julianDay == currentJulianDay + 1) { return context.getString(R.string.tomorrow); } else { Time time = new Time(); time.setToNow(); // Otherwise, the format is just the day of the week (e.g "Wednesday". SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE"); return dayFormat.format(dateInMillis); } }
From source file:com.example.android.sunshine.app.Utility.java
/** * Helper method to convert the database representation of the date into something to display * to users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return a user-friendly representation of the date. */// w w w . j av a2 s. co m public static String getFriendlyDayString(Context context, long dateInMillis, boolean displayLongToday) { // The day string for forecast uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Time time = new Time(); time.setToNow(); long currentTime = System.currentTimeMillis(); int julianDay = Time.getJulianDay(dateInMillis, time.gmtoff); int currentJulianDay = Time.getJulianDay(currentTime, time.gmtoff); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (displayLongToday && julianDay == currentJulianDay) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format(context.getString(formatId, today, getFormattedMonthDay(context, dateInMillis))); } else if (julianDay < currentJulianDay + 7) { // If the input date is less than a week in the future, just return the day name. return getDayName(context, dateInMillis); } else { // Otherwise, use the form "Mon Jun 3" SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd"); return shortenedDateFormat.format(dateInMillis); } }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static long setUpdateAlarm(Context context, boolean initial) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmintent = new Intent(context, AlarmReceiver.class); alarmintent.setAction(AlarmReceiver.ALARM_UPDATE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0); MyApp.LogDebug(LOG_TAG, "set update alarm"); long next_fetch; long interval; Time t = new Time(); t.setToNow(); long now = t.toMillis(true); if ((now >= MyApp.first_day_start) && (now < MyApp.last_day_end)) { interval = 2 * AlarmManager.INTERVAL_HOUR; next_fetch = now + interval;/*from w ww . java 2 s .c o m*/ } else if (now >= MyApp.last_day_end) { MyApp.LogDebug(LOG_TAG, "cancel alarm post congress"); alarmManager.cancel(pendingintent); return 0; } else { interval = AlarmManager.INTERVAL_DAY; next_fetch = now + interval; } if ((now < MyApp.first_day_start) && ((now + AlarmManager.INTERVAL_DAY) >= MyApp.first_day_start)) { next_fetch = MyApp.first_day_start; interval = 2 * AlarmManager.INTERVAL_HOUR; if (!initial) { MyApp.LogDebug(LOG_TAG, "update alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } } if (initial) { MyApp.LogDebug(LOG_TAG, "set initial alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } return interval; }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
private static String makePinNotificationContentText(Context context, ContentSet task) { boolean isAllDay = TaskFieldAdapters.ALLDAY.get(task); Time now = new Time(); now.setToNow(); now.minute--;// w w w . j av a 2 s .co m Time start = TaskFieldAdapters.DTSTART.get(task); Time due = TaskFieldAdapters.DUE.get(task); if (start != null && start.toMillis(true) > 0 && (now.before(start) || due == null)) { start.allDay = isAllDay; String startString = context.getString(R.string.notification_task_start_date, NotificationActionUtils.formatTime(context, start)); return startString; } if (due != null && due.toMillis(true) > 0) { due.allDay = isAllDay; String dueString = context.getString(R.string.notification_task_due_date, NotificationActionUtils.formatTime(context, due)); return dueString; } String description = TaskFieldAdapters.DESCRIPTION.get(task); if (description != null) { description = description.replaceAll("\\[\\s?\\]", "?").replaceAll("\\[[xX]\\]", ""); } return description; }
From source file:com.wso2.mobile.mdm.utils.ServerUtilities.java
public static String pushData(Map<String, String> params_in, Context context) { String response = ""; try {/* w w w .j a v a 2s . c o m*/ logger = new LoggerCustom(context); Time now = new Time(); now.setToNow(); String log_in = logger.readFileAsString("wso2log.txt"); String to_write = ""; if (CommonUtilities.DEBUG_MODE_ENABLED) { if (log_in != null && !log_in.equals("") && !log_in.equals("null")) { to_write = "<br> AGENT TO SERVER AT " + now.hour + ":" + now.minute + ": <br> CODE : " + params_in.get("code").toString() + "<br>MSG ID : " + params_in.get("msgID").toString() + "<br>==========================================================<br>" + log_in; } else { to_write = "<br> AGENT TO SERVER AT " + now.hour + ":" + now.minute + ": <br> CODE : " + params_in.get("code").toString() + "<br>MSG ID : " + params_in.get("msgID").toString() + "<br>==========================================================<br>"; } logger.writeStringAsFile(to_write, "wso2log.txt"); } response = sendWithTimeWait("notifications", params_in, "POST", context).get("response"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return response; }
From source file:org.gnucash.android.ui.util.RecurrenceViewClickListener.java
@Override public void onClick(View v) { FragmentManager fm = mActivity.getSupportFragmentManager(); Bundle b = new Bundle(); Time t = new Time(); t.setToNow(); b.putLong(RecurrencePickerDialogFragment.BUNDLE_START_TIME_MILLIS, t.toMillis(false)); b.putString(RecurrencePickerDialogFragment.BUNDLE_TIME_ZONE, t.timezone); // may be more efficient to serialize and pass in EventRecurrence b.putString(RecurrencePickerDialogFragment.BUNDLE_RRULE, mRecurrenceRule); RecurrencePickerDialogFragment rpd = (RecurrencePickerDialogFragment) fm .findFragmentByTag(FRAGMENT_TAG_RECURRENCE_PICKER); if (rpd != null) { rpd.dismiss();// w w w . ja v a 2 s . com } rpd = new RecurrencePickerDialogFragment(); rpd.setArguments(b); rpd.setOnRecurrenceSetListener(mRecurrenceSetListener); rpd.show(fm, FRAGMENT_TAG_RECURRENCE_PICKER); }
From source file:com.ewintory.footballscores.ui.adapter.PagerAdapter.java
public String getDayName(Context context, long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name.//from ww w .j a v a 2 s .com Time t = new Time(); t.setToNow(); int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff); int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff); if (julianDay == currentJulianDay) { return context.getString(R.string.today); } else if (julianDay == currentJulianDay + 1) { return context.getString(R.string.tomorrow); } else if (julianDay == currentJulianDay - 1) { return context.getString(R.string.yesterday); } else { Time time = new Time(); time.setToNow(); // Otherwise, the format is just the day of the week (e.g "Wednesday". return DAY_FORMAT.format(dateInMillis); } }
From source file:org.cinedroid.tasks.impl.RetrievePerformancesTask.java
/** * Removes any times which have passed from the list * /*from w w w .j a va 2 s . com*/ * @param results */ private void filterPastDates(final FilmDate filmDate) { Time currentTime = new Time(); currentTime.setToNow(); Time performanceDate = new Time(); String date = filmDate.getDate(); performanceDate.parse(date); // Check if the performance date is before the current time. This will only be true in the situation that the filmDate represents // the current day, as the cineworld api does not return dates which have passed. If the object is the current date, the film // performances need filtering. if (currentTime.after(performanceDate)) { for (Iterator<FilmPerformance> i = filmDate.getPerformances().iterator(); i.hasNext();) { String time = i.next().getTime().replace(":", ""); // Get the time with the : removed. performanceDate.parse(String.format("%sT%s00", date, time)); Log.d(TAG, String.format("Checking %s", performanceDate.format("%d %b %H:%M"))); if (currentTime.after(performanceDate)) { Log.d(TAG, String.format("Removed %s", performanceDate.format("%d %b %H:%M"))); i.remove(); } } } Log.d(TAG, String.format("Current Time %s", currentTime.toString())); }
From source file:com.cloudkick.monitoring.CheckState.java
public CheckState(JSONObject state) throws JSONException { // Grab the "whence" if available if (state.has("whence")) { whenceWireFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); whenceWireFormat.setTimeZone(TimeZone.getTimeZone("GMT")); String whenceString = state.getString("whence"); try {/* w ww . j a va 2 s .c o m*/ long whenceMillis = whenceWireFormat.parse(whenceString).getTime(); Time now = new Time(); now.setToNow(); long diffMillis = ((now.toMillis(true)) - whenceMillis); if (whenceMillis == 0) { whence = "never"; } else if (diffMillis < 3600 * 1000) { whence = String.format("%d m", diffMillis / (1000 * 60)); } else if (diffMillis < (24 * 3600 * 1000)) { long mins = (diffMillis / (1000 * 60)) % 60; long hours = (diffMillis / (1000 * 3600)); whence = String.format("%d h, %d m", hours, mins); } else if (diffMillis < (7 * 24 * 3600 * 1000)) { long hours = (diffMillis / (1000 * 60 * 60)) % 24; long days = (diffMillis / (1000 * 60 * 60 * 24)); whence = String.format("%d d, %d h", days, hours); } else { long days = (diffMillis / (1000 * 60 * 60 * 24)) % 7; long weeks = (diffMillis / (1000 * 60 * 60 * 24 * 7)); whence = String.format("%d w, %d d", weeks, days); } } catch (ParseException e) { whence = null; } } else { whence = null; } // Grab the "service_state" if available if (state.has("service_state")) { serviceState = state.getString("service_state"); } else { serviceState = "UNKNOWN"; } // Depending on the serviceState set the status and color if (serviceState.equals("OK")) { status = state.getString("status"); stateColor = 0xFF088A08; stateSymbol = "\u2714"; priority = 4; } else if (serviceState.equals("ERROR")) { status = state.getString("status"); stateColor = 0xFFE34648; stateSymbol = "\u2718"; priority = 0; } else if (serviceState.equals("WARNING")) { status = state.getString("status"); stateColor = 0xFFDF7401; stateSymbol = "!"; priority = 1; } else if (serviceState.equals("NO-AGENT")) { status = "Agent Not Connected"; stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 2; } else if (serviceState.equals("UNKNOWN")) { status = "No Data Available"; stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 3; } else { Log.e("Check", "Unknown Service State: " + serviceState); status = state.getString("status"); stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 3; } }