Example usage for android.text.format DateUtils FORMAT_24HOUR

List of usage examples for android.text.format DateUtils FORMAT_24HOUR

Introduction

In this page you can find the example usage for android.text.format DateUtils FORMAT_24HOUR.

Prototype

int FORMAT_24HOUR

To view the source code for android.text.format DateUtils FORMAT_24HOUR.

Click Source Link

Usage

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

public static void setTime(Activity activity, TextView view, long millis) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT;
    if (DateFormat.is24HourFormat(activity)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }//from w w w.  j a v a2 s  . c om

    // Unfortunately, DateUtils doesn't support a timezone other than the
    // default timezone provided by the system, so we have this ugly hack
    // here to trick it into formatting our time correctly. In order to
    // prevent all sorts of craziness, we synchronize on the TimeZone class
    // to prevent other threads from reading an incorrect timezone from
    // calls to TimeZone#getDefault()
    // TODO fix this if/when DateUtils allows for passing in a timezone
    String timeString;
    synchronized (TimeZone.class) {
        timeString = DateUtils.formatDateTime(activity, millis, flags);
        TimeZone.setDefault(null);
    }

    view.setTag(millis);
    view.setText(timeString);
}

From source file:nl.atcomputing.spacetravelagency.order.DepartureInfoService.java

private void sendNotification(long epochInMilliseconds) {

    /*/* ww  w .ja v  a  2 s .c  om*/
     * 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);
}

From source file:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

private String getTimeText(Shift shift) {
    String time = mIdToTimeArray.get((int) shift.id);
    if (!TextUtils.isEmpty(time))
        return time;

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24Hour)
        flags |= DateUtils.FORMAT_24HOUR;

    mStringBuilder.setLength(0);//ww w.  j  a  v  a 2 s .  c om
    time = DateUtils.formatDateRange(mContext, mFormatter, shift.getStartTime(), shift.getEndTime(), flags)
            .toString();

    time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")";

    mIdToTimeArray.put((int) shift.id, time);
    return time;
}

From source file:com.jaspersoft.android.jaspermobile.activities.storage.adapter.FileAdapter.java

private String getFormattedDateModified(File file) {
    return DateUtils.formatDateTime(getContext(), file.lastModified(),
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR
                    | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_24HOUR);
}

From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java

private String getTimeText(Shift shift) {
    String time = mIdToTimeArray.get((int) shift.id);
    if (!TextUtils.isEmpty(time))
        return time;

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24Hour)
        flags |= DateUtils.FORMAT_24HOUR;

    mStringBuilder.setLength(0);//from w  ww.  ja v  a  2s. com
    time = DateUtils.formatDateRange(getContext(), mFormatter, shift.getStartTime(), shift.getEndTime(), flags)
            .toString();

    time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")";

    mIdToTimeArray.put((int) shift.id, time);
    return time;
}

From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        super.onPopulateAccessibilityEvent(event);

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24HourView) {
        flags |= DateUtils.FORMAT_24HOUR;
    } else {/* www . j a  v a2  s  .  c om*/
        flags |= DateUtils.FORMAT_12HOUR;
    }
    mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour());
    mTempCalendar.set(Calendar.MINUTE, getCurrentMinute());
    String selectedDateUtterance = DateUtils.formatDateTime(getContext(), mTempCalendar.getTimeInMillis(),
            flags);
    event.getText().add(selectedDateUtterance);
}

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

@Override
public void onTimeSelected(long millis) {
    if (getActivity() == null)
        return;/*from   www.ja v a2 s. com*/

    TextView tv = null;
    if (mLastTimeSelected == LastTimeSelected.START)
        tv = mStartTime;
    else if (mLastTimeSelected == LastTimeSelected.END)
        tv = mEndTime;
    else
        return; //O no! This should never happen!

    tv.setTag(millis);

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (DateFormat.is24HourFormat(getActivity()))
        flags |= DateUtils.FORMAT_24HOUR;
    else
        flags |= DateUtils.FORMAT_12HOUR;

    tv.setError(null);
    tv.setText(DateUtils.formatDateRange(getActivity(), millis, millis, flags));
}

From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24HourView) {
        flags |= DateUtils.FORMAT_24HOUR;
    } else {//from  w  w w  .j  a  va  2 s.  com
        flags |= DateUtils.FORMAT_12HOUR;
    }
    mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour());
    mTempCalendar.set(Calendar.MINUTE, getCurrentMinute());
    String selectedDate = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags);
    event.getText().add(selectedDate);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);
    int flags = DateUtils.FORMAT_SHOW_TIME;

    // The deprecation status does not show up in the documentation and
    // source code does not outline the alternative.
    // Leaving this as is for now.
    if (mIs24HourView) {
        //noinspection deprecation
        flags |= DateUtils.FORMAT_24HOUR;
    } else {//w  w w  .  j a va2 s  .  c o m
        //noinspection deprecation
        flags |= DateUtils.FORMAT_12HOUR;
    }
    mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour());
    mTempCalendar.set(Calendar.MINUTE, getCurrentMinute());
    String selectedDate = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags);
    event.getText().add(selectedDate);
}