当前位置: 首页>>代码示例>>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;未经允许,请勿转载。