Java 类android.text.format.DateFormat 实例源码

项目:open-journal-android    文件:ExistingNoteActivity.java   
private void saveNote() {
    if(title.getText().toString().equals(noteTitle) && text.getText().toString().equals(notesdb.getData(noteId))) {
        // Note is unchanged, exit activity
        finish();
    } else {
        if(title.getText().toString().matches("[a-zA-Z0-9!?. ]+")) {
            // Update note
            if(DateFormat.is24HourFormat(this)) {
                notesdb.updateNote(noteId, title.getText().toString(), text.getText().toString(), new SimpleDateFormat("MM/dd/yyyy HH:mm", Locale.US).format(new Date()));
            } else {
                notesdb.updateNote(noteId, title.getText().toString(), text.getText().toString(), new SimpleDateFormat("MM/dd/yyyy hh:mm aa", Locale.US).format(new Date()));
            }
            finish();
        } else {
            unsupportedCharacters();
        }
    }
}
项目:zabbkit-android    文件:OldEventAdapter.java   
private ArrayList<EventDate> fillDates() {
    ArrayList<EventDate> eventDates = new ArrayList<EventDate>(mEventList.size());
    Map<String, Long> previousDurations = new ArrayMap<String, Long>();
    long previousDate = System.currentTimeMillis() / Constants.MS_IN_SEC;
    for (Event event : mEventList) {
        if (event != null && event.triggers != null && event.triggers.size() > 0) {
            long timestamp = Long.valueOf(event.getClock());
            CharSequence date = DateFormat.format(Constants.DATE_FORMAT, timestamp * Constants.MS_IN_SEC);
            String triggerId = event.triggers.get(0).triggerid;

            long duration;
            if (previousDurations.containsKey(triggerId)) {
                duration = previousDate - timestamp - previousDurations.get(triggerId);
                previousDurations.put(triggerId, duration + previousDurations.get(triggerId));
            } else {
                duration = previousDate - timestamp;
                previousDurations.put(triggerId, duration);
            }
            eventDates.add(new EventDate(date, duration));
        } else {
            eventDates.add(null);
        }
    }
    return eventDates;
}
项目:GitHub    文件:DateUtils.java   
public static String getShortTime(String dateStr) {
    String str;

    Date date = str2date(dateStr);
    Date curDate = new Date();

    long durTime = curDate.getTime() - date.getTime();
    int dayDiff = calculateDayDiff(date, curDate);

    if (durTime <= 10 * ONE_MINUTE_MILLIONS) {
        str = "刚刚";
    } else if (durTime < ONE_HOUR_MILLIONS) {
        str = durTime / ONE_MINUTE_MILLIONS + "分钟前";
    } else if (dayDiff == 0) {
        str = durTime / ONE_HOUR_MILLIONS + "小时前";
    } else if (dayDiff == -1) {
        str = "昨天" + DateFormat.format("HH:mm", date);
    } else if (isSameYear(date, curDate) && dayDiff < -1) {
        str = DateFormat.format("MM-dd", date).toString();
    } else {
        str = DateFormat.format("yyyy-MM", date).toString();
    }

    return str;
}
项目:GitHub    文件:RxAptStandardLinearActivity.java   
private MultiHeaderEntity getChangeItem(int itemType) {

        String date = (String) DateFormat.format("HH:mm:ss", System.currentTimeMillis());
        if (itemType == SimpleHelper.TYPE_ONE) {
            return new FirstItem("我的天,类型1被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_THREE) {
            return new SecondItem("我的天,类型2被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_FOUR) {
            return new ThirdItem("我的天,类型3被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_TWO) {
            return new FourthItem("我的天,类型4被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_ONE - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderFirstItem("我的天,类型1的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_THREE - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderSecondItem("我的天,类型2的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_FOUR - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderThirdItem("我的天,类型3的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_TWO - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderFourthItem("我的天,类型4的头被修改了 " + date);
        }
        return null;
    }
项目:GitHub    文件:RxMixedLinearActivity.java   
private MultiHeaderEntity getChangeItem() {

        Random random = new Random();
        int itemType = random.nextInt(4);

        String date = (String) DateFormat.format("HH:mm:ss", System.currentTimeMillis());
        if (itemType == SimpleHelper.TYPE_ONE) {
            return new FirstItem("我的天,类型1被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_THREE) {
            return new SecondItem("我的天,类型2被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_FOUR) {
            return new ThirdItem("我的天,类型3被修改了 " + date);
        }
        return new FourthItem("我的天,类型4被修改了 " + date);

    }
项目:GitHub    文件:RxStandardLinearActivity.java   
private MultiHeaderEntity getChangeItem(int itemType) {

        String date = (String) DateFormat.format("HH:mm:ss", System.currentTimeMillis());
        if (itemType == SimpleHelper.TYPE_ONE) {
            return new FirstItem("我的天,类型1被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_THREE) {
            return new SecondItem("我的天,类型2被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_FOUR) {
            return new ThirdItem("我的天,类型3被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_TWO) {
            return new FourthItem("我的天,类型4被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_ONE - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderFirstItem("我的天,类型1的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_THREE - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderSecondItem("我的天,类型2的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_FOUR - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderThirdItem("我的天,类型3的头被修改了 " + date);
        } else if (itemType == SimpleHelper.TYPE_TWO - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER) {
            return new HeaderFourthItem("我的天,类型4的头被修改了 " + date);
        }
        throw new RuntimeException("返回为空");
    }
项目:zabbkit-android    文件:EventAdapter.java   
private ArrayList<EventDate> fillDates() {
    ArrayList<EventDate> eventDates = new ArrayList<EventDate>(mObjectsList.size());
    Map<String, Long> previousDurations = new ArrayMap<String, Long>();
    long previousDate = System.currentTimeMillis() / Constants.MS_IN_SEC;
    for (Event event : (List<Event>) mObjectsList) {
        if (event != null && event.triggers != null && event.triggers.size() > 0) {
            long timestamp = Long.valueOf(event.getClock());
            CharSequence date = DateFormat.format(Constants.DATE_FORMAT, timestamp * Constants.MS_IN_SEC);
            String triggerId = event.triggers.get(0).triggerid;

            long duration;
            if (previousDurations.containsKey(triggerId)) {
                duration = previousDate - timestamp - previousDurations.get(triggerId);
                previousDurations.put(triggerId, duration + previousDurations.get(triggerId));
            } else {
                duration = previousDate - timestamp;
                previousDurations.put(triggerId, duration);
            }
            eventDates.add(new EventDate(date, duration));
        } else {
            eventDates.add(null);
        }
    }
    return eventDates;
}
项目:DateTimePicker    文件:DateFormatFix.java   
/**
 * Creates the best date-time pattern for the specified locale using the given skeleton. This
 * method works by calling {@link DateFormat#getBestDateTimePattern(Locale, String)} on API 18
 * and up, while returning a static pattern on lower API levels.
 *
 * @param context  the context that will be used on pre API 18 devices to guess the format
 * @param locale   the locale to be used as the formatting base (it might be ignored on pre API 18)
 * @param skeleton the skeleton for the pattern guesser / native method
 * @return A pattern that should be usable by formatters.
 * @see DateFormat
 * @see java.text.SimpleDateFormat
 */
public static String getBestDateTimePattern(Context context, Locale locale, String skeleton) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return DateFormat.getBestDateTimePattern(locale, skeleton);
    } else {
        switch (skeleton) {
            case SKELETON_Hm:
                return context.getString(R.string.datetime_Hm);
            case SKELETON_hm:
                return context.getString(R.string.datetime_hm);
            case SKELETON_EMMMd:
                return context.getString(R.string.datetime_EMMMd);
            case SKELETON_EMMMMdy:
                return context.getString(R.string.datetime_EMMMMdy);
            case SKELETON_MMMMy:
                return context.getString(R.string.datetime_MMMMy);

            default:
                throw new UnsupportedOperationException();
        }
    }
}
项目:A.scribe    文件:TimePickerDialogFragment.java   
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    DateTime currentDateTime = new DateTime();
    int currentHour = currentDateTime.getHourOfDay();
    int currentMinute = currentDateTime.getMinuteOfHour();
    final Bundle args = getArguments();

    MinTimePickerDialog timePickerDialog = new MinTimePickerDialog(getActivity(), R.style.MyPicker,
            (view, hourOfDay, minute) -> {
                DateTime dateTime = new DateTime(
                        args.getInt(ARGUMENT_PICKED_YEAR),
                        args.getInt(ARGUMENT_PICKED_MONTH) + 1,
                        args.getInt(ARGUMENT_PICKED_DAY), hourOfDay, minute);
                EventBus.getDefault().post(new ReminderSetEvent(dateTime.getMillis()));
            }, currentHour, currentMinute, DateFormat.is24HourFormat(getActivity()));
    if (args.getBoolean(ARGUMENT_IS_TODAY)) {
        timePickerDialog.setMin(currentHour, currentMinute);
    }

    return timePickerDialog;
}
项目:LiteReader    文件:ZhihuDailyListViewModel.java   
private void loadBeforeNews() {
    service.getBefore(DateFormat.format("yyyyMMdd", date).toString())
            .compose(new ThreadDispatcher<ZhihuDailyList>())
            .subscribe(new SimpleHttpSubscriber<ZhihuDailyList>() {
                @Override
                public void onNext(ZhihuDailyList zhihuDailyList) {
                    date = DateUtil.yesterday(date);
                    setIsLoadingMore(false);
                    getAdapter().add(new ZhihuDateItemViewModel(date));
                    initNews(zhihuDailyList.stories);
                }

                @Override
                protected void onFailed() {
                    setIsLoadingMore(false);
                }
            });
}
项目:Android-Code-Demos    文件:CrimeFragment.java   
private String getCrimeReport() {
   String solvedString = null;
   if (mCrime.isSolved()) {
       solvedString = getString(R.string.crime_report_solved);
   }else{
       solvedString = getString(R.string.crime_report_unsolved);
   }

   String dateFormat = "EEE, MMM dd";
   String dateString = DateFormat.format(dateFormat, mCrime.getDate()).toString();

   String suspect = mCrime.getSuspect();
   if (null == suspect) {
       suspect = getString(R.string.crime_report_no_suspect);
   }else{
       suspect = getString(R.string.crime_report_suspect, suspect);
   }

   String report = getString(R.string.crime_report, mCrime.getTitle(), dateString, solvedString, suspect);

   return report;
}
项目:android_packages_apps_ClockWidget    文件:ClockWidget.java   
private static void setClockAmPm(Context context, RemoteViews widget) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (DateFormat.is24HourFormat(context)) {
            widget.setViewVisibility(R.id.ampm_text, View.GONE);
        } else {
            widget.setViewVisibility(R.id.ampm_text, View.VISIBLE);
            Calendar currentCalendar = Calendar.getInstance();

            int hour = currentCalendar.get(Calendar.HOUR_OF_DAY);

            if (hour < 12) {
                widget.setTextViewText(R.id.ampm_text, context.getResources().getString(R.string.time_am_default));
            } else {
                widget.setTextViewText(R.id.ampm_text, context.getResources().getString(R.string.time_pm_default));
            }
        }
    }
    else{
        widget.setViewVisibility(R.id.ampm_text, View.GONE);
    }

}
项目:airgram    文件:LocaleController.java   
public void onDeviceConfigurationChange(Configuration newConfig) {
    if (changingConfiguration) {
        return;
    }
    is24HourFormat = DateFormat.is24HourFormat(ApplicationLoader.applicationContext);
    systemDefaultLocale = newConfig.locale;
    if (languageOverride != null) {
        LocaleInfo toSet = currentLocaleInfo;
        currentLocaleInfo = null;
        applyLanguage(toSet, false);
    } else {
        Locale newLocale = newConfig.locale;
        if (newLocale != null) {
            String d1 = newLocale.getDisplayName();
            String d2 = currentLocale.getDisplayName();
            if (d1 != null && d2 != null && !d1.equals(d2)) {
                recreateFormatters();
            }
            currentLocale = newLocale;
            currentPluralRules = allRules.get(currentLocale.getLanguage());
            if (currentPluralRules == null) {
                currentPluralRules = allRules.get("en");
            }
        }
    }
}
项目:YiZhi    文件:DateUtils.java   
public static String getShortTime(String dateStr) {
    String str;

    Date date = str2date(dateStr);
    Date curDate = new Date();

    long durTime = curDate.getTime() - date.getTime();
    int dayDiff = calculateDayDiff(date, curDate);

    if (durTime <= 10 * ONE_MINUTE_MILLIONS) {
        str = "刚刚";
    } else if (durTime < ONE_HOUR_MILLIONS) {
        str = durTime / ONE_MINUTE_MILLIONS + "分钟前";
    } else if (dayDiff == 0) {
        str = durTime / ONE_HOUR_MILLIONS + "小时前";
    } else if (dayDiff == -1) {
        str = "昨天" + DateFormat.format("HH:mm", date);
    } else if (isSameYear(date, curDate) && dayDiff < -1) {
        str = DateFormat.format("MM-dd", date).toString();
    } else {
        str = DateFormat.format("yyyy-MM", date).toString();
    }

    return str;
}
项目:orgzly-android    文件:MiscTest.java   
@Test
public void testTimestampDialogTimeButtonValueWhenToggling() {
    shelfTestUtils.setupBook("book-name", "Sample book used for tests\n" +
                                          "* TODO Note #1.\n" +
                                          "SCHEDULED: <2015-01-18 04:05 +6d>\n" +
                                          "* Note #2.\n" +
                                          "");
    activityRule.launchActivity(null);

    onView(allOf(withText("book-name"), isDisplayed())).perform(click());
    onListItem(1).perform(click());

    Calendar cal = new GregorianCalendar(2015, 0, 18, 4, 5);
    String s = DateFormat.getTimeFormat(InstrumentationRegistry.getTargetContext()).format(cal.getTime());

    onView(withId(R.id.fragment_note_scheduled_button)).perform(click());
    onView(withId(R.id.dialog_timestamp_time_picker)).check(matches(withText(containsString(s))));
    onView(withId(R.id.dialog_timestamp_time_check)).perform(scrollTo(), click());
    onView(withId(R.id.dialog_timestamp_time_picker)).check(matches(withText(containsString(s))));
    onView(withId(R.id.dialog_timestamp_time_check)).perform(click());
    onView(withId(R.id.dialog_timestamp_time_picker)).check(matches(withText(containsString(s))));
}
项目:event-me    文件:MessagingActivity.java   
private void sendFileFirebase(StorageReference storageReference, final Uri file) {
    if (storageReference != null) {
        final String name = DateFormat.format("yyyy-MM-dd_hhmmss", new Date()).toString();
        StorageReference imageGalleryRef = storageReference.child(name + "_gallery");
        UploadTask uploadTask = imageGalleryRef.putFile(file);
        uploadTask.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.e(TAG, "onFailure sendFileFirebase " + e.getMessage());
            }
        }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Log.i(TAG, "onSuccess sendFileFirebase");
                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                FileModel fileModel = new FileModel("img", downloadUrl.toString(), name, "");
                ChatModel chatModel = new ChatModel(userModel, "", Calendar.getInstance().getTime().getTime() + "", fileModel);
                mFirebaseDatabaseReference.child(Constants.events).child(evekey).child(Constants.chatmodel).push().setValue(chatModel);
            }
        });
    } else {
        //IS NULL
    }
}
项目:youkes_browser    文件:HelpUtils.java   
/**
 * save image from uri
 * @param outPath
 * @param bitmap
 * @return
 */
public static String saveBitmapToLocal(String outPath , Bitmap bitmap) {
    try {
        String imagePath = outPath + HelpUtils.md5(DateFormat.format("yyyy-MM-dd-HH-mm-ss", System.currentTimeMillis()).toString()) + ".jpg";
        File file = new File(imagePath);
        if(!file.exists()) {
            file.createNewFile();
        }
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bufferedOutputStream);
        bufferedOutputStream.close();
        LogUtil.d(TAG, "photo image from data, path:" + imagePath);
        return imagePath;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:AndroidProgramming3e    文件:CrimeFragment.java   
private String getCrimeReport() {
    String solvedString = null;
    if (mCrime.isSolved()) {
        solvedString = getString(R.string.crime_report_solved);
    } else {
        solvedString = getString(R.string.crime_report_unsolved);
    }
    String dateFormat = "EEE, MMM dd";
    String dateString = DateFormat.format(dateFormat, mCrime.getDate()).toString();
    String suspect = mCrime.getSuspect();
    if (suspect == null) {
        suspect = getString(R.string.crime_report_no_suspect);
    } else {
        suspect = getString(R.string.crime_report_suspect, suspect);
    }
    String report = getString(R.string.crime_report,
            mCrime.getTitle(), dateString, solvedString, suspect);
    return report;
}
项目:Android-Timeline-View    文件:TimeLineConfig.java   
public static void addObject(TimelineObject photo, TimelineGroupType type){
    long ts = photo.getTimestamp();
    Date date = new Date(ts);
    String day = (String) DateFormat.format("dd", date);
    String month = (String) DateFormat.format("MMM", date);
    String year = (String) DateFormat.format("yyyy", date);
    String tabTitle = "";
    switch (type) {
        case DAY:
            tabTitle = day + " " + month + ", " + year;
            break;
        case MONTH:
            tabTitle = month + ", " + year;
            break;
        case YEAR:
            tabTitle = year;
    }
    if(headerList.contains(tabTitle)){
        timelineObjMap.get(tabTitle).add(photo);
    }else {
        ArrayList<TimelineObject> _l = new ArrayList<>();
        _l.add(photo);
        headerList.add(tabTitle);
        timelineObjMap.put(tabTitle, _l);
    }
}
项目:zabbkit-android    文件:DataFragment.java   
@Override
public void onRequestSuccess(List<Object> result, Class<?> clazz) {
    if (isResumed()) {
        final List<ZabbixItem> items = new ArrayList<>();
        for (Object itemObj : result) {
            ZabbixItem item = (ZabbixItem) itemObj;
            if (item.getStatus() == ZabbixItem.STATUS_ENABLED) {
                items.add(item);
            }
        }
        if (mIsDataObsolete) {
            mIsDataObsolete = false;
        }
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                setAdapterData(items);
                mDateTimeUpdate = DateFormat.format(Constants.DATE_FORMAT,
                        System.currentTimeMillis());
                dismissDialog();
                completeListResfresh();
            }
        });
    }
}
项目:AndroidProgramming3e    文件:CrimeFragment.java   
private String getCrimeReport() {
    String solvedString = null;
    if (mCrime.isSolved()) {
        solvedString = getString(R.string.crime_report_solved);
    } else {
        solvedString = getString(R.string.crime_report_unsolved);
    }
    String dateFormat = "EEE, MMM dd";
    String dateString = DateFormat.format(dateFormat, mCrime.getDate()).toString();
    String suspect = mCrime.getSuspect();
    if (suspect == null) {
        suspect = getString(R.string.crime_report_no_suspect);
    } else {
        suspect = getString(R.string.crime_report_suspect, suspect);
    }
    String report = getString(R.string.crime_report,
            mCrime.getTitle(), dateString, solvedString, suspect);
    return report;
}
项目:EsperantoRadio    文件:DigitalClock.java   
private void updateTime() {
  if (mLive) {
    mCalendar.setTimeInMillis(System.currentTimeMillis());
  }

  CharSequence newTime = DateFormat.format(mFormat, mCalendar);
  mTimeDisplay.setText(newTime);
  mAmPm.setIsMorning(mCalendar.get(Calendar.AM_PM) == 0);
}
项目:lineagex86    文件:ZenModeScheduleRuleSettings.java   
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final boolean usePref = pref != null && pref.mHourOfDay >= 0 && pref.mMinute >= 0;
    final Calendar c = Calendar.getInstance();
    final int hour = usePref ? pref.mHourOfDay : c.get(Calendar.HOUR_OF_DAY);
    final int minute = usePref ? pref.mMinute : c.get(Calendar.MINUTE);
    return new TimePickerDialog(getActivity(), this, hour, minute,
            DateFormat.is24HourFormat(getActivity()));
}
项目:lineagex86    文件:ZenModeVoiceActivity.java   
/**
 * Produce a summary of the Zen mode change to be read aloud as TTS.
 */
private CharSequence getChangeSummary(int mode, int minutes) {
    int indefinite = -1;
    int byMinute = -1;
    int byHour = -1;
    int byTime = -1;

    switch (mode) {
        case Global.ZEN_MODE_ALARMS:
            indefinite = R.string.zen_mode_summary_alarms_only_indefinite;
            byMinute = R.plurals.zen_mode_summary_alarms_only_by_minute;
            byHour = R.plurals.zen_mode_summary_alarms_only_by_hour;
            byTime = R.string.zen_mode_summary_alarms_only_by_time;
            break;
        case Global.ZEN_MODE_OFF:
            indefinite = R.string.zen_mode_summary_always;
            break;
    };

    if (minutes < 0 || mode == Global.ZEN_MODE_OFF) {
        return getString(indefinite);
    }

    long time = System.currentTimeMillis() + minutes * MINUTES_MS;
    String skeleton = DateFormat.is24HourFormat(this, UserHandle.myUserId()) ? "Hm" : "hma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    CharSequence formattedTime = DateFormat.format(pattern, time);
    Resources res = getResources();

    if (minutes < 60) {
        return res.getQuantityString(byMinute, minutes, minutes, formattedTime);
    } else if (minutes % 60 != 0) {
        return res.getString(byTime, formattedTime);
    } else {
        int hours = minutes / 60;
        return res.getQuantityString(byHour, hours, hours, formattedTime);
    }
}
项目:q-mail    文件:TimePickerPreference.java   
@Override
protected View onCreateDialogView() {

    TimePicker tp = new TimePicker(getContext());
    tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));
    tp.setOnTimeChangedListener(this);
    originalHour = getHour();
    originalMinute = getMinute();
    if (originalHour >= 0 && originalMinute >= 0) {
        tp.setCurrentHour(originalHour);
        tp.setCurrentMinute(originalMinute);
    }

    return tp;
}
项目:boohee_v5.6    文件:MonthView.java   
protected CharSequence getItemDescription(int day) {
    this.mTempCalendar.set(MonthView.this.mYear, MonthView.this.mMonth, day);
    CharSequence date = DateFormat.format(DATE_FORMAT, this.mTempCalendar.getTimeInMillis
            ());
    if (day != MonthView.this.mSelectedDay) {
        return date;
    }
    return MonthView.this.getContext().getString(R.string.mdtp_item_is_selected, new
            Object[]{date});
}
项目:permitlog-android    文件:DriveTimeFragment.java   
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //Get the default time from the arguments:
    int hour = getArguments().getInt("hour");
    int minute = getArguments().getInt("minute");
    //Return a TimePickerDialog which has a default time of what was set in the constructor:
    return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}
项目:ForeverLibrary    文件:PhotoUtil.java   
@SuppressLint("SdCardPath")
private static String getPhotoPath(String form, String Name) {
    String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + form;
    String externalPath = ToolCache.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString();
    String pathname = externalPath + "/" + Name + "/";
    String fileName = pathname + name;
    File file = new File(pathname);
    if (!file.exists()) {
        Log.e("TAG", "第一次创建文件夹");
        file.mkdirs();// 如果文件夹不存在,则创建文件夹
    }
    return fileName;
}
项目:zabbkit-android    文件:ZabbixItemUtils.java   
public static String parseItemValue(ZabbixItem item) {
    String valueString;

    if (item.getValueType() == ZabbixItem.VALUE_TYPE_UINT
            || item.getValueType() == ZabbixItem.VALUE_TYPE_FLOAT) {
        final double value = Float.valueOf(item.getLastValue())
                * item.getFormula();
        final String unit = item.getUnits().trim();

        if ("uptime".equals(unit)) {
            valueString = TimeParser.parseTime((long) value);
        } else if ("unixtime".equals(unit)) {
            valueString = DateFormat.format(Constants.DATE_FORMAT,
                    (long) value * Constants.MS_IN_SEC).toString();
        } else if ("B".equals(unit) || "bps".equals(unit)) {
            if (item.getValueType() == ZabbixItem.VALUE_TYPE_UINT) {
                valueString = ValueConvertUtils.convertInteger(
                        (long) value, unit);
            } else {
                valueString = ValueConvertUtils.convertFloat(value, unit);
            }
        } else {
            if (item.getValueType() == ZabbixItem.VALUE_TYPE_UINT) {
                valueString = String.format(Locale.ENGLISH, "%d %s",
                        (long) value, unit);
            } else {
                valueString = String.format(Locale.ENGLISH, "%.3f %s",
                        value, unit);
            }
        }
    } else {
        valueString = item.getLastValue();
    }

    return valueString;
}
项目:trust-wallet-android    文件:TransactionDateHolder.java   
@Override
    public void bind(@Nullable Date data, @NonNull Bundle addition) {
        if (data == null) {
            title.setText(null);
        } else {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
            calendar.setTime(data);
//            java.text.DateFormat dateFormat = DateFormat.getMediumDateFormat(getContext());
//            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
//            title.setText(dateFormat.format(calendar.getTime()));
            title.setText(DateFormat.format(DATE_TEMPLATE, calendar));
        }
    }
项目:FamilyLibraryManager    文件:InputFragment.java   
/**
 * 显示时间捡取器
 */
private void showDatePickerDialog() {
    new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            showDate.set(Calendar.YEAR, year);
            showDate.set(Calendar.MONTH, monthOfYear);
            showDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            bookDateEditText.setText(DateFormat.format("yyyy-MM-dd", showDate));
        }
    }, showDate.get(Calendar.YEAR), showDate.get(Calendar.MONTH), showDate.get(Calendar.DAY_OF_MONTH)).show();
}
项目:LiteReader    文件:DateUtil.java   
public static String toFriendlyFormat(Date date) {
    long now = new Date().getTime();
    long target = date.getTime();
    long diff = now - target;
    int days = (int) Math.ceil(diff / (24 * 60 * 60 * 1000));
    switch (days) {
        case 1:
            return "昨天";
        case 2:
            return "两天前";
        default:
            return DateFormat.format("yyyy-MM-dd", date).toString() + " " + getWeekDay(date);
    }
}
项目:Android-Development    文件:TimePickerFragment.java   
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current time as the default values for the picker
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    // Create a new instance of TimePickerDialog and return it
    return new TimePickerDialog(getActivity(), this, hour, minute,
            DateFormat.is24HourFormat(getActivity()));
}
项目:Sprog-App    文件:PoemsListAdapter.java   
@NonNull
@Override
public String getSectionName(int position) {
    if (presenter.sort_order.equals("Date")) {
        cal.setTimeInMillis((long) filtered_poems.get(position).timestamp * 1000);
        return DateFormat.format("yyyy-MM", cal).toString();
    } else if (presenter.sort_order.equals("Score")) {
        return Integer.toString(filtered_poems.get(position).score);
    } else if (presenter.sort_order.equals("Gold")) {
        return Integer.toString(filtered_poems.get(position).gold);
    }
    return "";
}
项目:PeSanKita-android    文件:DateUtils.java   
public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale locale) {
  String dateFormatPattern;

  if (DateFormat.is24HourFormat(context)) {
    dateFormatPattern = getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale);
  } else {
    dateFormatPattern = getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale);
  }

  return new SimpleDateFormat(dateFormatPattern, locale);
}
项目:PeSanKita-android    文件:DateUtils.java   
private static String getLocalizedPattern(String template, Locale locale) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    return DateFormat.getBestDateTimePattern(locale, template);
  } else {
    return new SimpleDateFormat(template, locale).toLocalizedPattern();
  }
}
项目:AssistantBySDK    文件:MonthView.java   
@NonNull
private String getMonthAndYearString() {
    Locale locale = Locale.getDefault();
    String pattern = "MMMM yyyy";

    if(Build.VERSION.SDK_INT < 18) pattern = getContext().getResources().getString(R.string.mdtp_date_v1_monthyear);
    else pattern = DateFormat.getBestDateTimePattern(locale, pattern);

    SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
    formatter.applyLocalizedPattern(pattern);
    mStringBuilder.setLength(0);
    return formatter.format(mCalendar.getTime());
}
项目:AssistantBySDK    文件:MonthView.java   
/**
 * Generates a description for a given time object. Since this
 * description will be spoken, the components are ordered by descending
 * specificity as DAY MONTH YEAR.
 *
 * @param day The day to generate a description for
 * @return A description of the time object
 */
protected CharSequence getItemDescription(int day) {
    mTempCalendar.set(mYear, mMonth, day);
    final CharSequence date = DateFormat.format(DATE_FORMAT,
            mTempCalendar.getTimeInMillis());

    if (day == mSelectedDay) {
        return getContext().getString(R.string.mdtp_item_is_selected, date);
    }

    return date;
}
项目:Minimal-Todo    文件:AddToDoActivity.java   
public void setDate(int year, int month, int day){
        Calendar calendar = Calendar.getInstance();
        int hour, minute;
//        int currentYear = calendar.get(Calendar.YEAR);
//        int currentMonth = calendar.get(Calendar.MONTH);
//        int currentDay = calendar.get(Calendar.DAY_OF_MONTH);

        Calendar reminderCalendar = Calendar.getInstance();
        reminderCalendar.set(year, month, day);

        if(reminderCalendar.before(calendar)){
            Toast.makeText(this, "My time-machine is a bit rusty", Toast.LENGTH_SHORT).show();
            return;
        }

        if(mUserReminderDate!=null){
            calendar.setTime(mUserReminderDate);
        }

        if(DateFormat.is24HourFormat(this)){
            hour = calendar.get(Calendar.HOUR_OF_DAY);
        }
        else{

            hour = calendar.get(Calendar.HOUR);
        }
        minute = calendar.get(Calendar.MINUTE);

        calendar.set(year, month, day, hour, minute);
        mUserReminderDate = calendar.getTime();
        setReminderTextView();
//        setDateAndTimeEditText();
        setDateEditText();
    }
项目:SOS-The-Healthcare-Companion    文件:DateAndTimeUtil.java   
public static String toStringReadableTime(Calendar calendar, Context context) {
    if (DateFormat.is24HourFormat(context)) {
        return READABLE_TIME_24_FORMAT.format(calendar.getTime());
    } else {
        return READABLE_TIME_FORMAT.format(calendar.getTime());
    }
}