當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormat類代碼示例

本文整理匯總了Java中android.text.format.DateFormat的典型用法代碼示例。如果您正苦於以下問題:Java DateFormat類的具體用法?Java DateFormat怎麽用?Java DateFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DateFormat類屬於android.text.format包,在下文中一共展示了DateFormat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBestDateTimePattern

import android.text.format.DateFormat; //導入依賴的package包/類
/**
 * 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();
        }
    }
}
 
開發者ID:Gericop,項目名稱:DateTimePicker,代碼行數:34,代碼來源:DateFormatFix.java

示例2: saveNote

import android.text.format.DateFormat; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:zanedb,項目名稱:open-journal-android,代碼行數:19,代碼來源:ExistingNoteActivity.java

示例3: fillDates

import android.text.format.DateFormat; //導入依賴的package包/類
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;
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:26,代碼來源:OldEventAdapter.java

示例4: getShortTime

import android.text.format.DateFormat; //導入依賴的package包/類
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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:DateUtils.java

示例5: getChangeItem

import android.text.format.DateFormat; //導入依賴的package包/類
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;
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:RxAptStandardLinearActivity.java

示例6: getChangeItem

import android.text.format.DateFormat; //導入依賴的package包/類
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);

    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:RxMixedLinearActivity.java

示例7: getChangeItem

import android.text.format.DateFormat; //導入依賴的package包/類
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("返回為空");
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:RxStandardLinearActivity.java

示例8: fillDates

import android.text.format.DateFormat; //導入依賴的package包/類
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;
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:26,代碼來源:EventAdapter.java

示例9: onCreateDialog

import android.text.format.DateFormat; //導入依賴的package包/類
@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;
}
 
開發者ID:Laaidback,項目名稱:A.scribe,代碼行數:23,代碼來源:TimePickerDialogFragment.java

示例10: loadBeforeNews

import android.text.format.DateFormat; //導入依賴的package包/類
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);
                }
            });
}
 
開發者ID:Mindjet,項目名稱:LiteReader,代碼行數:19,代碼來源:ZhihuDailyListViewModel.java

示例11: getCrimeReport

import android.text.format.DateFormat; //導入依賴的package包/類
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;
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:23,代碼來源:CrimeFragment.java

示例12: setClockAmPm

import android.text.format.DateFormat; //導入依賴的package包/類
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);
    }

}
 
開發者ID:WeAreFairphone,項目名稱:android_packages_apps_ClockWidget,代碼行數:23,代碼來源:ClockWidget.java

示例13: onDeviceConfigurationChange

import android.text.format.DateFormat; //導入依賴的package包/類
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");
            }
        }
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:27,代碼來源:LocaleController.java

示例14: testTimestampDialogTimeButtonValueWhenToggling

import android.text.format.DateFormat; //導入依賴的package包/類
@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))));
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:23,代碼來源:MiscTest.java

示例15: sendFileFirebase

import android.text.format.DateFormat; //導入依賴的package包/類
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
    }
}
 
開發者ID:picopalette,項目名稱:event-me,代碼行數:25,代碼來源:MessagingActivity.java


注:本文中的android.text.format.DateFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。