Java Code Examples for android.text.format.DateFormat#format()
The following examples show how to use
android.text.format.DateFormat#format() .
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: ModifyInfoActivity.java From BaoKanAndroid with MIT License | 6 votes |
/** * 使用相机拍照 */ 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); }
Example 2
Source File: SimpleWavRecorderHandler.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
/** * Get the file to record to for a given remote contact. This will * implicitly get the current date in file name. * * @param remoteContact The remote contact name * @return The file to store conversation */ private File getRecordFile(File dir, String remoteContact, int way) { if (dir != null) { // The file name is only to have an unique identifier. // It should never be used to store datas as may change. // The app using the recording files should rely on the broadcast // and on callInfo instead that is reliable. String datePart = (String) DateFormat.format("yy-MM-dd_kkmmss", new Date()); String remotePart = sanitizeForFile(remoteContact); String fileName = datePart + "_" + remotePart; if (way != (SipManager.BITMASK_ALL)) { fileName += ((way & SipManager.BITMASK_IN) == 0) ? "_out" : "_in"; } File file = new File(dir.getAbsoluteFile() + File.separator + fileName + ".wav"); return file; } return null; }
Example 3
Source File: DataBaseOperations.java From minx with MIT License | 6 votes |
public void saveDataInDB(String title, String url, String body) { // ' (single apostrophe) doesn't work with sqlite database in insertion, instead of it, use ''(double apostrophe). tldr : store ' as '' otherwise it won't work title=title.replace("'","''"); body=body.replace("'","''"); Date date = new Date(); CharSequence initTime = DateFormat.format("yyyy-MM-dd hh:mm:ss", date.getTime()); String time = initTime.toString(); DataBaseAdapter dbAdapter = new DataBaseAdapter(context); dbAdapter.createDatabase(); dbAdapter.open(); String query = "INSERT INTO webpage (title, url, desc, date) " + "VALUES ('" + title + "', '" + url + "', '" + body + "', '" + time + "')"; dbAdapter.executeQuery(query); dbAdapter.close(); Toast.makeText(context, "Data saved successfully", Toast.LENGTH_SHORT).show(); }
Example 4
Source File: PublishedActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * 调用系统相机 */ public void takePhoto() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// 调用系统相机 new DateFormat(); String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; Uri imageUri = Uri.fromFile(new File(PATH, name)); path = PATH + "/" + name; intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, TAKE_PICTURE); }
Example 5
Source File: MonthView.java From StyleableDateTimePicker with MIT License | 5 votes |
/** * 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.item_is_selected, date); } return date; }
Example 6
Source File: CrashHandler.java From Mupdf with Apache License 2.0 | 5 votes |
private void writeLogcat(String name) { CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis()); String filename = name + "_" + timestamp + ".log"; try { Logcat.writeLogcat(filename); } catch (IOException e) { Log.e(TAG, "Cannot write logcat to disk"); } }
Example 7
Source File: LibreReceiver.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static double calculateWeightedAverage(List<Libre2RawValue> rawValues, long now) { double sum = 0; double weightSum = 0; DecimalFormat longformat = new DecimalFormat( "#,###,###,##0.00" ); libre_calc_doku=""; for (Libre2RawValue rawValue : rawValues) { double weight = 1 - ((now - rawValue.timestamp) / (double) SMOOTHING_DURATION); sum += rawValue.glucose * weight; weightSum += weight; libre_calc_doku += DateFormat.format("kk:mm:ss :",rawValue.timestamp) + " w:" + longformat.format(weight) +" raw: " + rawValue.glucose + "\n" ; } return Math.round(sum / weightSum); }
Example 8
Source File: SimpleMonthView.java From SublimePicker with Apache License 2.0 | 5 votes |
/** * Generates a description for a given virtual view. * * @param id the day to generate a description for * @return a description of the virtual view */ private CharSequence getDayDescription(int id) { if (isValidDayOfMonth(id)) { mTempCalendar.set(mYear, mMonth, id); return DateFormat.format(DATE_FORMAT, mTempCalendar.getTimeInMillis()); } return ""; }
Example 9
Source File: LibreReceiver.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static double calculateWeightedAverage(List<Libre2RawValue> rawValues, long now) { double sum = 0; double weightSum = 0; DecimalFormat longformat = new DecimalFormat( "#,###,###,##0.00" ); libre_calc_doku=""; for (Libre2RawValue rawValue : rawValues) { double weight = 1 - ((now - rawValue.timestamp) / (double) SMOOTHING_DURATION); sum += rawValue.glucose * weight; weightSum += weight; libre_calc_doku += DateFormat.format("kk:mm:ss :",rawValue.timestamp) + " w:" + longformat.format(weight) +" raw: " + rawValue.glucose + "\n" ; } return Math.round(sum / weightSum); }
Example 10
Source File: NotesAdapter.java From Paperwork-Android with MIT License | 5 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.note_item, parent, false); TextView noteTitle = (TextView) rowView.findViewById(R.id.note_title); TextView notePreview = (TextView) rowView.findViewById(R.id.note_preview); TextView noteDay = (TextView) rowView.findViewById(R.id.note_day); TextView noteMonth = (TextView) rowView.findViewById(R.id.note_month); TextView noteYear = (TextView) rowView.findViewById(R.id.note_year); String title = mNotes.get(position).getTitle(); String preview = mNotes.get(position).getPreview(); preview = Html.fromHtml(preview).toString(); Date date = mNotes.get(position).getUpdatedAt(); String day = (String) DateFormat.format("dd", date); String month = (String) DateFormat.format("MMM", date); String year = (String) DateFormat.format("yyyy", date); noteTitle.setText(title); noteTitle.setVisibility(title.length() == 0 ? View.GONE : View.VISIBLE); notePreview.setText(preview); noteDay.setText(day); noteMonth.setText(month); noteYear.setText(year); return rowView; }
Example 11
Source File: MonthView.java From cathode with Apache License 2.0 | 5 votes |
/** * 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.item_is_selected, date); } return date; }
Example 12
Source File: TwilightState.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public String toString() { return "TwilightState {" + " sunrise=" + DateFormat.format("MM-dd HH:mm", mSunriseTimeMillis) + " sunset="+ DateFormat.format("MM-dd HH:mm", mSunsetTimeMillis) + " }"; }
Example 13
Source File: RxMixedLinearActivity.java From MultiTypeRecyclerViewAdapter with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: RxMixedLinearActivity.java From MultiTypeRecyclerViewAdapter with Apache License 2.0 | 5 votes |
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); }
Example 15
Source File: MonthView.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 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; }
Example 16
Source File: SimpleMonthView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Generates a description for a given virtual view. * * @param id the day to generate a description for * @return a description of the virtual view */ private CharSequence getDayDescription(int id) { if (isValidDayOfMonth(id)) { mTempCalendar.set(mYear, mMonth, id); return DateFormat.format(DATE_FORMAT, mTempCalendar.getTimeInMillis()); } return ""; }
Example 17
Source File: ZenModeConfig.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Creates readable time from time in milliseconds */ public static CharSequence getFormattedTime(Context context, long time, boolean isSameDay, int userHandle) { String skeleton = (!isSameDay ? "EEE " : "") + (DateFormat.is24HourFormat(context, userHandle) ? "Hm" : "hma"); final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); return DateFormat.format(pattern, time); }
Example 18
Source File: Bill.java From rally with Apache License 2.0 | 4 votes |
@Override public String getRowSecondaryString() { return "Due " + DateFormat.format("MMM dd", mDueDate); }
Example 19
Source File: NotificationEntry.java From Android-Notification with Apache License 2.0 | 2 votes |
/** * Set a timestamp pertaining to this notification. * * Only used for: * @see NotificationLocal * @see NotificationGlobal * * @param format * @param when */ public void setWhen(CharSequence format, long when) { if (format == null) format = DEFAULT_DATE_FORMAT; this.whenFormatted = DateFormat.format(format, when); }
Example 20
Source File: TimeUtil.java From iMoney with Apache License 2.0 | 2 votes |
/** * 返回几天前的日期 * * @param day 天数 * @return 2017-03-11 */ public static String getBeforeDate(int day) { CharSequence sysTimeStr = DateFormat.format("yyyy-MM-dd", (System.currentTimeMillis() - (24 * 60 * 60 * 1000) * day)); return String.valueOf(sysTimeStr); }