public static String prettyTimestamp(Timestamp t, boolean isChat) { // Set time in UTC time Time time = new Time("UTC"); Calendar cal = Calendar.getInstance(); cal.setTime(t); time.set( cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH), cal.get(Calendar.YEAR)); // Switch to device timezone time.switchTimezone(Time.getCurrentTimezone()); Time startOfDay = new Time(Time.getCurrentTimezone()); startOfDay.setToNow(); startOfDay.hour = 0; startOfDay.minute = 0; startOfDay.second = 0; Time startOfYear = new Time(Time.getCurrentTimezone()); startOfYear.setToNow(); startOfYear.hour = 0; startOfYear.minute = 0; startOfYear.second = 0; startOfYear.monthDay = 0; startOfYear.month = 0; Time startOfTime = new Time(Time.getCurrentTimezone()); startOfTime.set(0); if (t.equals(new Timestamp(0, 0, 0, 0, 0, 0, 0))) { return ""; } else if (isChat) { if (time.after(startOfDay)) { return time.format("%H:%M"); } else if (time.after(startOfYear)) { return time.format("%b %d, %H:%M"); } else { return time.format("%b %d %Y, %H:%M"); } } else { if (time.after(startOfDay)) { return time.format("%H:%M"); } else if (time.after(startOfYear)) { return time.format("%b %d"); } else { return time.format("%b %d %Y"); } } }
private static void a(Context paramContext, File paramFile) { FileOutputStream localFileOutputStream = new FileOutputStream(paramFile); byte[] arrayOfByte1 = Settings.Secure.getString(paramContext.getContentResolver(), "android_id").getBytes(); Time localTime = new Time(); localTime.setToNow(); byte[] arrayOfByte2 = new byte[6 + arrayOfByte1.length]; for (int i = 0; ; i++) { if (i >= arrayOfByte1.length) { int j = i + 1; arrayOfByte2[i] = ((byte) localTime.year); int k = j + 1; arrayOfByte2[j] = ((byte) localTime.month); int m = k + 1; arrayOfByte2[k] = ((byte) localTime.monthDay); int n = m + 1; arrayOfByte2[m] = ((byte) localTime.hour); int i1 = n + 1; arrayOfByte2[n] = ((byte) localTime.minute); arrayOfByte2[i1] = ((byte) localTime.second); String str = UUID.nameUUIDFromBytes(arrayOfByte2).toString(); System.out.println("uuid.." + str); localFileOutputStream.write(str.getBytes()); return; } arrayOfByte2[i] = arrayOfByte1[i]; } }
public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }
/** Return the time the workout was completed for a given workout id. */ private Time getTimeForWorkout(int workoutId) { Cursor cursor = null; try { cursor = mDatabase.query( DATABASE_TABLE_WENDLER_WORKOUT, new String[] {KEY_WORKOUT_YEAR, KEY_WORKOUT_MONTH, KEY_WORKOUT_DAY}, KEY_WORKOUT_ID + "=?", new String[] {String.valueOf(workoutId)}, null, null, null); Time time = new Time(); time.setToNow(); if (cursor != null && cursor.moveToFirst()) { time.year = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_YEAR))); time.month = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_MONTH))); time.monthDay = Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_WORKOUT_DAY))); } return time; } finally { if (cursor != null) { cursor.close(); } } }
public int getDueDay() { Time time = getTime(taskData.end_date); Time now = new Time(); now.setToNow(); long diff = time.toMillis(true) - now.toMillis(true); return (int) (diff / (1000 * 60 * 60 * 24)); }
@Override protected void updateQueryParameters(QueryParams params) { if (params.getUpdatedMin() == null) { // if this is the first sync, only bother syncing starting from // one month ago. // TODO: remove this restriction -- we may want all of // historical calendar events. Time lastMonth = new Time(Time.TIMEZONE_UTC); lastMonth.setToNow(); --lastMonth.month; lastMonth.normalize(true /* ignore isDst */); String startMin = lastMonth.format("%Y-%m-%dT%H:%M:%S.000Z"); // TODO: move start-min to CalendarClient? // or create CalendarQueryParams subclass (extra class)? params.setParamValue("start-min", startMin); // HACK: specify that we want to expand recurrences ijn the past, // so the server does not expand any recurrences. we do this to // avoid a large number of gd:when elements that we do not need, // since we process gd:recurrence elements instead. params.setParamValue("recurrence-expansion-start", "1970-01-01"); params.setParamValue("recurrence-expansion-end", "1970-01-01"); } // we want to get the events ordered by last modified, so we can // recover in case we cannot process the entire feed. params.setParamValue("orderby", "lastmodified"); params.setParamValue("sortorder", "ascending"); }
@Override protected void onResume() { super.onResume(); AppMeasurementUtils appMeasurementProm = new AppMeasurementUtils(NewLimitbuyActivity.this); appMeasurementProm.getUrl( getString(R.string.appMeas_actiCenter) + ":" + getString(R.string.appMeas_groupprom), getString(R.string.appMeas_actiCenter), getString(R.string.appMeas_actiCenter) + ":" + getString(R.string.appMeas_groupprom), getString(R.string.appMeas_groupprom), "", "", "", "", "", "", "", "", getString(R.string.appMeas_myprom), "", "", "", null); Time t2 = new Time(); t2.setToNow(); boolean isorNo = t2.after(t); if (isorNo) { setData(true, true); BDebug.d("liuyang", "我也执行了"); t.set(0, 0, 24, t2.monthDay, t2.month, t2.year); } }
/** * Helper method to convert the database representation of the date into something to display to * users. As classy and polished a user experience as "20140102" is, we can do better. * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return a user-friendly representation of the date. */ public static String getFriendlyDayString(Context context, long dateInMillis) { // The day string for forecast uses the following logic: // For today: "Today, June 8" // For tomorrow: "Tomorrow" // For the next 5 days: "Wednesday" (just the day name) // For all days after that: "Mon Jun 8" Time time = new Time(); time.setToNow(); long currentTime = System.currentTimeMillis(); int julianDay = Time.getJulianDay(dateInMillis, time.gmtoff); int currentJulianDay = Time.getJulianDay(currentTime, time.gmtoff); // If the date we're building the String for is today's date, the format // is "Today, June 24" if (julianDay == currentJulianDay) { String today = context.getString(R.string.today); int formatId = R.string.format_full_friendly_date; return String.format( context.getString(formatId, today, getFormattedMonthDay(context, dateInMillis))); } else if (julianDay < currentJulianDay + 7) { // If the input date is less than a week in the future, just return the day name. return getDayName(context, dateInMillis); } else { // Otherwise, use the form "Mon Jun 3" SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd"); return shortenedDateFormat.format(dateInMillis); } }
private void setWhenDefaults() { // it's possible to have: // 1) no times set // 2) due time set, but not start time // 3) start and due time set mShowStart = !Time.isEpoch(mStartTime); mShowDue = !Time.isEpoch(mDueTime); if (!mShowStart && !mShowDue) { mStartTime.setToNow(); // Round the time to the nearest half hour. mStartTime.second = 0; int minute = mStartTime.minute; if (minute > 0 && minute <= 30) { mStartTime.minute = 30; } else { mStartTime.minute = 0; mStartTime.hour += 1; } long startMillis = mStartTime.normalize(true /* ignore isDst */); mDueTime.set(startMillis + DateUtils.HOUR_IN_MILLIS); } else if (!mShowStart) { // default start to same as due mStartTime.set(mDueTime); } }
protected void doTakePhoto() { try { // Launch camera to take photo for selected contact PHOTO_DIR.mkdirs(); // 创建照片的存储目录 Time t = new Time(); t.setToNow(); String year = String.valueOf(t.year); String month = String.valueOf(t.month + 1); String day = String.valueOf(t.monthDay); String hour; if (t.hour < 10) { hour = "0" + String.valueOf(t.hour); } else { hour = String.valueOf(t.hour); } String minute; if (t.minute < 10) { minute = "0" + String.valueOf(t.minute); } else { minute = String.valueOf(t.minute); } String second; if (t.second < 10) { second = "0" + String.valueOf(t.second); } else { second = String.valueOf(t.second); } String filenameString = "lily_" + year + month + day + hour + minute + second + ".jpeg"; File outFile = new File(PHOTO_DIR, filenameString); final Intent intent = getTakePickIntent(outFile); startActivityForResult(intent, CAMERA_WITH_DATA); } catch (ActivityNotFoundException e) { Toast.makeText(this, "无法创建图片", Toast.LENGTH_LONG).show(); } }
@Override public void populateView( View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { TextView title = (TextView) view.findViewById(android.R.id.title); if (title != null) { String text = cursor.getString(5); title.setText(text); } Integer status = cursor.getInt(11); TextView dueDateField = (TextView) view.findViewById(R.id.task_due_date); if (dueDateField != null) { Time dueDate = Common.DUE_ADAPTER.get(cursor); if (dueDate != null) { if (mNow == null) { mNow = new Time(); } mNow.clear(TimeZone.getDefault().getID()); mNow.setToNow(); if (status == null || status < Tasks.STATUS_COMPLETED) { dueDateField.setText(makeDueDate(dueDate)); // highlight overdue dates & times if (dueDate.before(mNow)) { dueDateField.setTextColor(Color.RED); } else { dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80)); } } else { Long completed = cursor.getLong(12); if (completed != null) { Time complTime = new Time(Time.TIMEZONE_UTC); complTime.set(completed); dueDateField.setText(makeDueDate(complTime)); // highlight if the task has been completed after the due date if (dueDate.after(complTime)) { dueDateField.setTextColor(Color.RED); } else { dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80)); } } else { // TODO: what do we show then there is no completed date? } } } else { dueDateField.setText(""); } } View colorbar = view.findViewById(R.id.colorbar); if (colorbar != null) { colorbar.setBackgroundColor(cursor.getInt(6)); } }
public static byte[] getCurrentTimeData() { /* * org.bluetooth.characteristic.current_time * - Exact Time 256: org.bluetooth.characteristic.exact_time_256 * - Day Date Time: org.bluetooth.characteristic.day_date_time * - Date Time: org.bluetooth.characteristic.date_time * - Year: uint16 * - Month: uint8 * - Day: uint8 * - Hours: uint8 * - Minutes: uint8 * - Seconds: uint8 * - Day of Week: org.bluetooth.characteristic.day_of_week * - uint8 * - Fractions256: uint8 * - Adjust Reason: 8bit */ Time currentTime = new Time(); currentTime.setToNow(); byte[] timeData = new byte[10]; timeData[0] = (byte) (currentTime.year % 256); timeData[1] = (byte) (currentTime.year / 256); timeData[2] = (byte) (currentTime.month + 1); timeData[3] = (byte) (currentTime.monthDay); timeData[4] = (byte) (currentTime.hour); timeData[5] = (byte) (currentTime.minute); timeData[6] = (byte) (currentTime.second); timeData[7] = (byte) (currentTime.weekDay + 1); timeData[8] = 0; timeData[9] = 0; return timeData; }
public static String getCurYearAndMonth() { Time time = new Time(); time.setToNow(); int year = time.year; int month = time.month + 1; return year + "_" + month; }
@Override public NdefMessage createNdefMessage(NfcEvent event) { Log.d("ANDROID_LAB", "createNdefMessage thread.name=" + Thread.currentThread().getName()); StringBuilder sb = new StringBuilder(); sb.append(Build.MODEL + "("); // 手机型号 sb.append(Build.VERSION.SDK_INT + ","); // SDK版本号 sb.append(Build.VERSION.RELEASE + ")"); // Firmware/OS 版本号 sb.append("发送来一条NFC消息, 时间是"); Time time = new Time(); time.setToNow(); sb.append(time.format("%H:%M:%S")); Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.and); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] bmpData = baos.toByteArray(); NdefRecord[] records = new NdefRecord[2]; records[0] = NdefRecord.createMime("application/lab.sodino.nfc", sb.toString().getBytes()); // 文本消息 records[1] = NdefRecord.createMime("application/lab.sodino.nfc", bmpData); // 图片消息 // records[2] = NdefRecord.createApplicationRecord("com.tencent.mobileqq"); NdefMessage msg = new NdefMessage(records); return msg; }
protected void onTimeChanged() { calendar.setToNow(); mHour = calendar.hour; mMinute = calendar.minute; mChanged = true; }
// 获得20150926格式的当前日期 public static int getCurrentTime() { Time time = new Time("GMT+8"); time.setToNow(); int year = time.year * 10000; int month = (time.month + 1) * 100; int day = time.monthDay; return year + month + day; }
@Override public void onPause() { super.onPause(); Time tm = new Time(); tm.setToNow(); beforeSuspend = tm.minute * 60 + tm.second; tm1.append("\nGoto Suspend time: " + beforeSuspend); }
// Helper functions to convert the DB DepartureTime value public static long convertDBToTime(int minutes) { // This converts the minutes-to-midnight to a time of the current // day. Time t = new Time(); t.setToNow(); t.set(0, minutes, 0, t.monthDay, t.month, t.year); return t.toMillis(false); }
protected void log(boolean error, String msg) { android.text.format.Time time = new android.text.format.Time(); time.setToNow(); Log.i(TAG, "log: " + msg); log.append(COLOR_TIME, time.format("%H:%M:%S\t")) .append(error ? COLOR_ERROR : COLOR_LOG, msg) .append("\n"); }
/** * Converts db date format to the format "Month day", e.g "June 24". * * @param context Context to use for resource localization * @param dateInMillis The db formatted date string, expected to be of the form specified in * Utility.DATE_FORMAT * @return The day in the form of a string formatted "December 6" */ public static String getFormattedMonthDay(Context context, long dateInMillis) { Time time = new Time(); time.setToNow(); SimpleDateFormat dbDateFormat = new SimpleDateFormat(Utility.DATE_FORMAT); SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd"); String monthDayString = monthDayFormat.format(dateInMillis); return monthDayString; }
public static void setLoggedInRightNow(SharedPreferences loginSettings) { Time now = new Time(); now.setToNow(); long milliseconds = now.toMillis(false) + 10800000; // 3 hours expired sessions Editor editor = loginSettings.edit(); editor.putLong("timeLoggedIn", milliseconds); editor.commit(); }
// *sanding function ... private boolean sendChatMessage() { Time now = new Time(); now.setToNow(); String apptime = Integer.toString(now.hour) + ":" + Integer.toString(now.second); abp.add(new ChatMessage(side, chattext.getText().toString() + "\n" + apptime)); chattext.setText(""); // *side = !side; return true; }
/* Denne konstructør skal anvendes når der startes et nyt løb. her new'es nyt uuid op, og tiden sættes. */ public LoebsAktivitet() { pointInfoList = new ArrayList<PointInfo>(); Time time = new Time(); time.setToNow(); starttidspunkt = time.toMillis(false); loebsAktivitetUuid = UUID.randomUUID(); loebsDato = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); }
private String getReportFileName(CrashReportData crashData) { final Time now = new Time(); now.setToNow(); final long timestamp = now.toMillis(false); final String isSilent = crashData.getProperty(IS_SILENT); return "" + timestamp + (isSilent != null ? ACRAConstants.SILENT_SUFFIX : "") + ACRAConstants.REPORTFILE_EXTENSION; }
public static String GetTodayText() { Time today = new Time(); today.setToNow(); int year = today.year; int month = today.month + 1; int day = today.monthDay; String date = String.format("%d/%d/%d", year, month, day); return date; }
void syncVideo() { VideoView view = (VideoView) findViewById(R.id.videoView1); Time time = new Time(); time.setToNow(); current = time.hour / 6; int offset = ((time.hour % 6) * 3600000) + (time.minute * 60000) + (time.second * 1000); view.setVideoURI(uris.get(current)); view.seekTo(offset); view.start(); }
/** * Given a day, returns just the name to use for that day. E.g "today", "tomorrow", "wednesday". * * @param context Context to use for resource localization * @param dateInMillis The date in milliseconds * @return */ public static String getDayName(Context context, long dateInMillis) { // If the date is today, return the localized version of "Today" instead of the actual // day name. Time t = new Time(); t.setToNow(); int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff); int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff); if (julianDay == currentJulianDay) { return context.getString(R.string.today); } else if (julianDay == currentJulianDay + 1) { return context.getString(R.string.tomorrow); } else { Time time = new Time(); time.setToNow(); // Otherwise, the format is just the day of the week (e.g "Wednesday". SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE"); return dayFormat.format(dateInMillis); } }
public static String getNowTime() { Time time = new Time(); time.setToNow(); int year = time.year; int month = time.month + 1; int day = time.monthDay; int minute = time.minute; int hour = time.hour; int sec = time.second; return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + sec; }
@Override public NdefMessage createNdefMessage(NfcEvent event) { Time time = new Time(); time.setToNow(); String text = ("Beam me up!\n\n" + "Beam Time: " + time.format("%H:%M:%S")); NdefMessage msg = new NdefMessage( new NdefRecord[] { createMimeRecord("application/com.example.android.beam", text.getBytes()) }); return msg; }
/** Creates Time container and sets its field to time of creation; */ public TimeContainer() { Time time = new Time(); time.setToNow(); second = time.second; minute = time.minute; hour = time.hour; day = time.monthDay; // due to java date lib month = time.month + 1; year = time.year; }