本文整理汇总了Java中android.text.format.DateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.format方法的具体用法?Java DateFormat.format怎么用?Java DateFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.DateFormat
的用法示例。
在下文中一共展示了DateFormat.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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("返回为空");
}
示例4: 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;
}
示例5: 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);
}
示例6: 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;
}
示例7: addObject
import android.text.format.DateFormat; //导入方法依赖的package包/类
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);
}
}
示例8: takePhoto
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* 使用相机拍照
*/
private void takePhoto() {
// 图片路径
tempPath = Environment.getExternalStorageDirectory() + "/DCIM/" + DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
// 创建拍照时的临时文件
File tempFile = new File(tempPath);
try {
if (tempFile.exists()) {
tempFile.delete();
}
tempFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
// 指定照片保存路径(SD卡),image.jpg为一个临时文件,每次拍照后这个图片都会被替换
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("return-data", false);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
startActivityForResult(intent, TAKE_PICTURE);
overridePendingTransition(R.anim.column_show, R.anim.column_bottom);
}
示例9: getChangeSummary
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* 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);
}
}
示例10: getAddItem
import android.text.format.DateFormat; //导入方法依赖的package包/类
private MultiHeaderEntity getAddItem() {
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);
}
示例11: enableAlert
import android.text.format.DateFormat; //导入方法依赖的package包/类
/**
* Sets alert in AlarmManger and StatusBar. This is what will
* actually launch the alert when the alarm triggers.
* @param alarm Alarm.
* @param atTimeInMillis milliseconds since epoch
*/
private static void enableAlert(Context context, final Alarm alarm,
final long atTimeInMillis) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Log.d("** setAlert atTime " + new Date(atTimeInMillis) + " -- " + alarm);
Intent intent = new Intent(ALARM_ALERT_ACTION);
intent.putExtra(ALARM_RAW_DATA, alarm.toString());
PendingIntent sender = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);
setStatusBarIcon(context, true);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(atTimeInMillis);
Kanal nyKanal = App.grunddata.kanalFraKode.get(alarm.kanalo);
if (nyKanal == null) {
Log.rapporterFejl(new IllegalStateException("Alarm: Kanal findes ikke!"), alarm.kanalo + " var ikke i "+ App.grunddata.kanalFraKode.keySet() );
nyKanal = App.grunddata.forvalgtKanal;
}
String message = nyKanal.navn +"\n"+DateFormat.format(DM24, c);
if (App.fejlsøgning) App.kortToast("Næste alarm sat til:\n"+message);
/* writing to settings requires android.permission.WRITE_SETTINGS
Settings.System.putString(App.instans.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, message);
*/
}
示例12: getPhotoPath
import android.text.format.DateFormat; //导入方法依赖的package包/类
@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;
}
示例13: writeDataBase
import android.text.format.DateFormat; //导入方法依赖的package包/类
private void writeDataBase(String message){
// Write a message to the database
FirebaseApp.initializeApp(getActivity());
FirebaseDatabase database = FirebaseDatabase.getInstance();
Calendar mCal = Calendar.getInstance();
CharSequence s = DateFormat.format("yyyy-MM-dd kk:mm:ss", mCal.getTime());
DatabaseReference myRef = database.getReference((String) s);
myRef.setValue(message);
}
示例14: updateTime
import android.text.format.DateFormat; //导入方法依赖的package包/类
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);
}
示例15: makeDateString
import android.text.format.DateFormat; //导入方法依赖的package包/类
private CharSequence makeDateString(Concert concert) {
int currentYear = new GregorianCalendar().get(Calendar.YEAR);
GregorianCalendar concertCalendar = new GregorianCalendar();
concertCalendar.setTime(concert.getDate());
int concertYear = concertCalendar.get(Calendar.YEAR);
String dateFormatString =
currentYear == concertYear ? thisYearDateFormat : anotherYearDateFormat;
return DateFormat.format(dateFormatString, concert.getDate());
}