List of usage examples for android.text.format DateUtils FORMAT_SHOW_DATE
int FORMAT_SHOW_DATE
To view the source code for android.text.format DateUtils FORMAT_SHOW_DATE.
Click Source Link
From source file:Main.java
/** * * @param context//w ww . j a v a 2s. com * @return string label */ public static String getRefreshTime(Context context) { String label = DateUtils.formatDateTime(context, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); return label; }
From source file:Main.java
public static String formatDate(Context context, long date) { int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME; return DateUtils.formatDateTime(context, date, format_flags); }
From source file:Main.java
public static String formatToDateFull(Context context, long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY); }
From source file:Main.java
public static String formatToDateNoYear(Context context, long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_24HOUR | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY); }
From source file:Main.java
/** * Returns a String formatted in the default locale of the device. Looks like "Ddd, Mmm dd, H:MMTT - H:MMTT * @param context the {@link android.content.Context} that this is running within. * @param start the starting date and time of this entry. * @param end the ending date and time of this entry. *///from w w w. j a v a2 s . c o m public static String buildTimeEntryDateAndTime(Context context, Calendar start, Calendar end) { return DateUtils.formatDateRange(context, start.getTimeInMillis(), end.getTimeInMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_NO_YEAR); }
From source file:Main.java
public static String formatDateTime(Context context, long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); Date d = new Date(time); int currentYear = Calendar.getInstance().get(Calendar.YEAR); int year = Integer.parseInt(TextUtils.isDigitsOnly(sdf.format(d)) ? sdf.format(d) : currentYear + ""); if (currentYear == year) { return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE //| DateUtils.FORMAT_SHOW_WEEKDAY //| DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH //| DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME); } else {//from w ww. ja va 2 s .c om return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE //| DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH //| DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME); } }
From source file:Main.java
@SuppressWarnings("deprecation") public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);/* ww w.j av a 2 s . c o m*/ Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make // showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }
From source file:Main.java
/** * Returns a date string in the format specified, which shows an abbreviated date without a * year.//from w ww . j av a 2s.com * * @param context Used by DateUtils to format the date in the current locale * @param timeInMillis Time in milliseconds since the epoch (local time) * * @return The formatted date string */ private static String getReadableDateString(Context context, long timeInMillis) { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY; return DateUtils.formatDateTime(context, timeInMillis, flags); }
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) { String twitterSearch = "http://search.twitter.com/search.json?q=" + tag; ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid // with this formatter SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); try {//ww w .ja va2 s .c om Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon); JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("results"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url")); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("created_at")); } catch (ParseException e) { Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at")); e.printStackTrace(); } String user = jsonItem.getString("from_user"); SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"), formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str"); newItem.setLink(link); socialItems.add(newItem); } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return socialItems; }
From source file:nl.atcomputing.spacetravelagency.order.DepartureInfoService.java
private void sendNotification(long epochInMilliseconds) { /*//from w ww. j a va2 s .co m * Unclear what should replace it. Official docs do not mention FORMAT_24HOUR as deprecated */ @SuppressWarnings("deprecation") CharSequence dateString = DateUtils.formatDateTime(this, epochInMilliseconds, DateUtils.FORMAT_24HOUR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); Intent intent = new Intent(this, PlaceOrderActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); @SuppressWarnings("deprecation") Notification notification = builder.setContentIntent(pi).setSmallIcon(R.drawable.ic_notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.spaceship_launcher)) .setTicker(getString(R.string.departure_time_changed)).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.departure_time_changed_to_) + dateString).getNotification(); nm.notify(1, notification); }