List of usage examples for android.text.format DateFormat getTimeFormat
public static java.text.DateFormat getTimeFormat(Context context)
From source file:Main.java
public static String formatTime(Context ctx, long time) { return DateFormat.getTimeFormat(ctx).format(new Date(time)); }
From source file:Main.java
public static String formatDateTime(Context ctx, long time) { Date d = new Date(time); return DateFormat.getDateFormat(ctx).format(d) + " " + DateFormat.getTimeFormat(ctx).format(d); }
From source file:Main.java
public static String getDisplayDateTime(Context context, long milli) { Date date = new Date(milli); if (System.currentTimeMillis() - milli < 60 * 60 * 24 * 1000l) { return DateFormat.getTimeFormat(context).format(date); }//from w w w .j a v a 2s . c o m return DateFormat.getDateFormat(context).format(date) + " " + DateFormat.getTimeFormat(context).format(date); }
From source file:Main.java
/** @param time input in seconds and already in proper timezone @return time in GMT0 timezone/*from ww w. j av a2 s .c o m*/ */ public static String getTimeStamp(Context context, long time) { java.text.DateFormat df = DateFormat.getTimeFormat(context); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(new Date(time * 1000L)); }
From source file:Main.java
public static String getDisplayTimeOrDate(Context context, long milli) { Date date = new Date(milli); if (System.currentTimeMillis() - milli > 60 * 60 * 24 * 1000l) { return DateFormat.getDateFormat(context).format(date); } else {//w w w .j a v a 2 s .c o m return DateFormat.getTimeFormat(context).format(date); } }
From source file:Main.java
/** * Returns the given timestamp formatted as date and time for the default locale. * @param context context/*from w w w . j a v a 2 s. co m*/ * @param timestamp timestamp to format * @return String timestamp formatted as date and time */ public static String getDateTimeString(final Context context, final long timestamp) { Date date = new Date(timestamp); String dateString = DateFormat.getLongDateFormat(context).format(date); String timeString = DateFormat.getTimeFormat(context).format(date); return String.format("%s %s", dateString, timeString); }
From source file:Main.java
/** * Returns the given timestamp formatted as short date and time for the default locale. * @param context context// w w w .j av a2 s . c om * @param timestamp timestamp to format * @return String timestamp formatted as date and time */ public static String getShortDateTimeString(final Context context, final long timestamp) { Date date = new Date(timestamp); String dateString = DateFormat.getDateFormat(context).format(date); String timeString = DateFormat.getTimeFormat(context).format(date); return String.format("%s %s", dateString, timeString); }
From source file:ch.citux.td.util.FormatUtils.java
public static String formateDate(Date date) { StringBuilder result = new StringBuilder(); result.append(DateFormat.getDateFormat(TDApplication.getContext()).format(date)); result.append(" "); result.append(DateFormat.getTimeFormat(TDApplication.getContext()).format(date)); return result.toString(); }
From source file:com.dgsd.android.ShiftTracker.Adapter.TemplateAdapter.java
public TemplateAdapter(Context context) { super(context, R.layout.list_item_template, null, new String[] { DbField.ID.name }, new int[] { R.id.container }, 0); this.setViewBinder(this); mTimeFormat = DateFormat.getTimeFormat(context); //Caching//from ww w. jav a 2 s.c o m mIdToTimeArray = new SparseArray<String>(); }
From source file:org.chromium.chrome.browser.notifications.CustomNotificationBuilder.java
@Override public Notification build() { RemoteViews compactView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification); RemoteViews bigView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_big); String time = DateFormat.getTimeFormat(mContext).format(new Date()); for (RemoteViews view : new RemoteViews[] { compactView, bigView }) { view.setTextViewText(R.id.time, time); view.setTextViewText(R.id.title, mTitle); view.setTextViewText(R.id.body, mBody); view.setTextViewText(R.id.origin, mOrigin); view.setImageViewBitmap(R.id.icon, mLargeIcon); }/* w w w . ja v a 2 s . co m*/ if (!mActions.isEmpty()) { bigView.setViewVisibility(R.id.button_divider, View.VISIBLE); bigView.setViewVisibility(R.id.buttons, View.VISIBLE); for (Action action : mActions) { RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button); button.setTextViewCompoundDrawablesRelative(R.id.button, action.getIcon(), 0, 0, 0); button.setTextViewText(R.id.button, action.getTitle()); button.setOnClickPendingIntent(R.id.button, action.getActionIntent()); bigView.addView(R.id.buttons, button); } } NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setTicker(mTickerText); builder.setSmallIcon(mSmallIconId); builder.setContentIntent(mContentIntent); builder.setDeleteIntent(mDeleteIntent); builder.setDefaults(mDefaults); builder.setVibrate(mVibratePattern); builder.setContent(compactView); Notification notification = builder.build(); notification.bigContentView = bigView; return notification; }