Java Code Examples for java.text.SimpleDateFormat#getTimeInstance()

The following examples show how to use java.text.SimpleDateFormat#getTimeInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComAdminImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public SimpleDateFormat getTimeFormat() {
	SimpleDateFormat timeFormat = (SimpleDateFormat) SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT, getLocale());
	timeFormat.setTimeZone(TimeZone.getTimeZone(getAdminTimezone()));
	timeFormat.setLenient(false);
	return timeFormat;
}
 
Example 2
Source File: Helper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
static DateFormat getTimeInstance(Context context, int style) {
    if (context != null &&
            (style == SimpleDateFormat.SHORT || style == SimpleDateFormat.MEDIUM)) {
        Locale locale = Locale.getDefault();
        boolean is24Hour = android.text.format.DateFormat.is24HourFormat(context);
        String skeleton = (is24Hour ? "Hm" : "hm");
        if (style == SimpleDateFormat.MEDIUM)
            skeleton += "s";
        String pattern = android.text.format.DateFormat.getBestDateTimePattern(locale, skeleton);
        return new SimpleDateFormat(pattern, locale);
    } else
        return SimpleDateFormat.getTimeInstance(style);
}
 
Example 3
Source File: DateTimeConverter.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
public static String msTimeToShortTimeString(long msTime) {
    Date date = new Date(msTime);
    DateFormat df = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    return df.format(date);
}
 
Example 4
Source File: NewEventActivity.java    From RoomBookerMVP with MIT License 4 votes vote down vote up
private void initDateTimeFormat() {
    simpleTimeFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
    simpleDateFormat = SimpleDateFormat.getDateInstance();
}
 
Example 5
Source File: TimeUtils.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected DateFormat initialValue() {
    return SimpleDateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
}
 
Example 6
Source File: GoogleCalendarService.java    From Speculum-Android with MIT License 4 votes vote down vote up
@SuppressWarnings("all")
public Observable<String> getCalendarEvents() {
    String details, title;
    Cursor cursor;
    ContentResolver contentResolver = application.getContentResolver();
    final String[] colsToQuery = new String[]{
            CalendarContract.EventsEntity.TITLE,
            CalendarContract.EventsEntity.DTSTART,
            CalendarContract.EventsEntity.DTEND,
            CalendarContract.EventsEntity.EVENT_LOCATION};

    Calendar now = Calendar.getInstance();
    SimpleDateFormat startFormat = new SimpleDateFormat(Constants.SIMPLEDATEFORMAT_DDMMYY, Locale.getDefault());
    String dateString = startFormat.format(now.getTime());
    long start = now.getTimeInMillis();

    SimpleDateFormat endFormat = new SimpleDateFormat(Constants.SIMPLEDATEFORMAT_HHMMSSDDMMYY, Locale.getDefault());
    Calendar endOfDay = Calendar.getInstance();
    Date endOfDayDate;
    try {
        endOfDayDate = endFormat.parse(Constants.END_OF_DAY_TIME + dateString);
        endOfDay.setTime(endOfDayDate);
    } catch (ParseException e) {
        Log.e(GoogleCalendarService.class.getSimpleName(), e.toString());
        throw new RuntimeException(String.format("ParseException occured: %s", e.getLocalizedMessage()));
    }

    cursor = contentResolver.query(CalendarContract.Events.CONTENT_URI, colsToQuery,
            Constants.CALENDAR_QUERY_FIRST + start + Constants.CALENDAR_QUERY_SECOND + endOfDay.getTimeInMillis() + Constants.CALENDAR_QUERY_THIRD,
            null, Constants.CALENDAR_QUERY_FOURTH);

    if (cursor != null) {
        if (cursor.getCount() > 0) {
            StringBuilder stringBuilder = new StringBuilder();
            while (cursor.moveToNext()) {
                title = cursor.getString(0);
                Calendar startTime = Calendar.getInstance();
                startTime.setTimeInMillis(cursor.getLong(1));
                Calendar endTime = Calendar.getInstance();
                endTime.setTimeInMillis(cursor.getLong(2));
                DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
                details = formatter.format(startTime.getTime()) + " - " + formatter.format(endTime.getTime());
                if (!TextUtils.isEmpty(cursor.getString(3))) {
                    details += " " + application.getString(R.string.at) + " " + cursor.getString(3);
                }
                stringBuilder.append(title + ", " + details);
                if (!cursor.isLast()) {
                    stringBuilder.append(" | ");
                }
            }
            cursor.close();
            return Observable.just(stringBuilder.toString());
        } else {
            cursor.close();
            return Observable.just(application.getString(R.string.no_events_today));
        }
    } else {
        throw new RuntimeException(application.getString(R.string.no_events_error));
    }
}
 
Example 7
Source File: DateUtil.java    From Klyph with MIT License 4 votes vote down vote up
private static String getFormattedTime(Date date)
{
	SimpleDateFormat timeFormat = (SimpleDateFormat) SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);

	return timeFormat.format(date);
}
 
Example 8
Source File: ChannelChatFragment.java    From Plumble with GNU General Public License v3.0 4 votes vote down vote up
public ChannelChatAdapter(Context context, IJumbleService service, List<IChatMessage> messages) {
    super(context, 0, new ArrayList<>(messages));
    mService = service;
    mImageGetter = new MumbleImageGetter(context);
    mDateFormat = SimpleDateFormat.getTimeInstance();
}
 
Example 9
Source File: EasyConfigMod.java    From easydeviceinfo with Apache License 2.0 2 votes vote down vote up
/**
 * Gets formatted time.
 *
 * @return the formatted time
 */
public final String getFormattedTime() {
  DateFormat timeInstance = SimpleDateFormat.getTimeInstance();
  return timeInstance.format(Calendar.getInstance().getTime());
}
 
Example 10
Source File: EasyConfigMod.java    From easydeviceinfo with Apache License 2.0 2 votes vote down vote up
/**
 * Gets formatted up time.
 *
 * @return the formatted up time
 */
public final String getFormattedUpTime() {
  DateFormat timeInstance = SimpleDateFormat.getTimeInstance();
  return timeInstance.format(SystemClock.uptimeMillis());
}