List of usage examples for android.text.format Time format
public String format(String format)
From source file:Main.java
public static String getTimeStamp() { Time now = new Time(); now.setToNow();//from w w w . j ava 2 s.co m String sTime = now.format("%Y_%m_%d_%H_%M_%S"); return sTime; }
From source file:Main.java
public static String now() { Time localTime = new Time(); localTime.setToNow();//from w w w.j a va2s . com return localTime.format("%Y%m%d%H%M%S"); }
From source file:Main.java
public static String getTimeAndDate(long j) { try {/*from w w w . j av a2 s.c o m*/ Calendar instance = Calendar.getInstance(); TimeZone timeZone = TimeZone.getDefault(); instance.setTimeInMillis(j); instance.add(14, timeZone.getOffset(instance.getTimeInMillis())); String format = new SimpleDateFormat(" dd, MMM yyyy").format(instance.getTime()); Time time = new Time(); time.set(j); return time.format("%H:%M") + format; } catch (Exception e) { return ""; } }
From source file:Main.java
/** * @return String//from w w w.j a v a2 s . co m * @throws * @Title: getTime * @Description: TODO */ public static String now() { Time nowTime = new Time("Asia/chongqing"); nowTime.setToNow(); return nowTime.format("%Y%m%d"); }
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Schedules an alarm for the EVENT_REMINDER_APP broadcast, for the specified * alarm time with a slight delay (to account for the possible duplicate broadcast * from the provider).//from w w w . j a va 2 s. c om */ private static void scheduleAlarm(Context context, long eventId, long alarmTime, long currentMillis, AlarmManagerInterface alarmManager) { // Max out the alarm time to 1 day out, so an alert for an event far in the future // (not present in our event query results for a limited range) can only be at // most 1 day late. long maxAlarmTime = currentMillis + MAX_ALARM_ELAPSED_MS; if (alarmTime > maxAlarmTime) { alarmTime = maxAlarmTime; } // Add a slight delay (see comments on the member var). alarmTime += ALARM_DELAY_MS; if (AlertService.DEBUG) { Time time = new Time(); time.set(alarmTime); String schedTime = time.format("%a, %b %d, %Y %I:%M%P"); Log.d(TAG, "Scheduling alarm for EVENT_REMINDER_APP broadcast for event " + eventId + " at " + alarmTime + " (" + schedTime + ")"); } // Schedule an EVENT_REMINDER_APP broadcast with AlarmManager. The extra is // only used by AlertService for logging. It is ignored by Intent.filterEquals, // so this scheduling will still overwrite the alarm that was previously pending. // Note that the 'setClass' is required, because otherwise it seems the broadcast // can be eaten by other apps and we somehow may never receive it. Intent intent = new Intent(AlertReceiver.EVENT_REMINDER_APP_ACTION); intent.setClass(context, AlertReceiver.class); intent.putExtra(CalendarContract.CalendarAlerts.ALARM_TIME, alarmTime); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:org.mozilla.gecko.FilePickerResultHandler.java
public String generateImageName() { Time now = new Time(); now.setToNow();//from ww w . j a v a2 s. c om mImageName = now.format("%Y-%m-%d %H.%M.%S") + ".jpg"; return mImageName; }
From source file:com.android.calendar.event.CreateEventDialogFragment.java
public void setDay(Time day) { mDateString = day.format(EVENT_DATE_FORMAT); mDateInMillis = day.toMillis(true); }
From source file:net.xisberto.work_schedule.alarm.CountdownService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { if (ACTION_START.equals(intent.getAction())) { if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) { int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID, R.string.fstp_entrance); period = Period.getPeriod(this, period_id); } else { stopSelf();//from www. ja va 2s . co m return super.onStartCommand(intent, flags, startId); } long millisInFuture = period.time.getTimeInMillis() - System.currentTimeMillis(); if (millisInFuture > 0) { Intent mainIntent = new Intent(this, MainActivity.class); mainIntent.setAction(MainActivity.ACTION_SET_PERIOD); mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent deleteIntent = new Intent(this, CountdownService.class); deleteIntent.setAction(ACTION_STOP); builder = new Builder(this).setSmallIcon(R.drawable.ic_stat_notification) .setContentTitle(getString(period.getLabelId())) .setTicker(getString(period.getLabelId())).setOnlyAlertOnce(true) .setPriority(NotificationCompat.PRIORITY_LOW).setAutoCancel(false) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(PendingIntent.getActivity(this, period.getId(), mainIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setDeleteIntent(PendingIntent.getService(this, period.getId(), deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT)); manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)); manager.notify(0, builder.build()); timer = new CountDownTimer(millisInFuture, 1000) { @Override public void onTick(long millisUntilFinished) { Time t = new Time(); t.set(millisUntilFinished); builder.setContentText(getString(R.string.time_until_alarm, t.format("%M:%S"))); manager.notify(0, builder.build()); } @Override public void onFinish() { manager.cancel(0); stopSelf(); } }; timer.start(); } } else if (ACTION_STOP_SPECIFIC.equals(intent.getAction())) { if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) { int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID, R.string.fstp_entrance); if (period != null && period.getId() == period_id) { stopAndCancel(); } } else { stopSelf(); return super.onStartCommand(intent, flags, startId); } } else if (ACTION_STOP.equals(intent.getAction())) { stopAndCancel(); } } return super.onStartCommand(intent, flags, startId); }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static void addAlarm(Context context, Lecture lecture, int alarmTimesIndex) { int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 }; long when;//from w ww . j a v a2 s. c om Time time; long startTime; long startTimeInSeconds = lecture.dateUTC; if (startTimeInSeconds > 0) { when = startTimeInSeconds; startTime = startTimeInSeconds; time = new Time(); } else { time = lecture.getTime(); startTime = time.normalize(true); when = time.normalize(true); } long alarmTimeDiffInSeconds = alarm_times[alarmTimesIndex] * 60 * 1000; when -= alarmTimeDiffInSeconds; // DEBUG // when = System.currentTimeMillis() + (30 * 1000); time.set(when); MyApp.LogDebug("addAlarm", "Alarm time: " + time.format("%Y-%m-%dT%H:%M:%S%z") + ", in seconds: " + when); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture.lecture_id); intent.putExtra(BundleKeys.ALARM_DAY, lecture.day); intent.putExtra(BundleKeys.ALARM_TITLE, lecture.title); intent.putExtra(BundleKeys.ALARM_START_TIME, startTime); intent.setAction(AlarmReceiver.ALARM_LECTURE); intent.setData(Uri.parse("alarm://" + lecture.lecture_id)); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id), intent, 0); // Cancel any existing alarms for this lecture alarmManager.cancel(pendingintent); // Set new alarm alarmManager.set(AlarmManager.RTC_WAKEUP, when, pendingintent); int alarmTimeInMin = alarm_times[alarmTimesIndex]; // write to DB AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context); SQLiteDatabase db = alarmDB.getWritableDatabase(); // delete any previous alarms of this lecture try { db.beginTransaction(); db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id }); ContentValues values = new ContentValues(); values.put(AlarmsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id)); values.put(AlarmsTable.Columns.EVENT_TITLE, lecture.title); values.put(AlarmsTable.Columns.ALARM_TIME_IN_MIN, alarmTimeInMin); values.put(AlarmsTable.Columns.TIME, when); DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); values.put(AlarmsTable.Columns.TIME_TEXT, df.format(new Date(when))); values.put(AlarmsTable.Columns.DISPLAY_TIME, startTime); values.put(AlarmsTable.Columns.DAY, lecture.day); db.insert(AlarmsTable.NAME, null, values); db.setTransactionSuccessful(); } catch (SQLException e) { } finally { db.endTransaction(); db.close(); } lecture.has_alarm = true; }
From source file:org.zapto.samhippiemiddlepoolchecker.Values.java
public void save() { //stores everything as sharedpreferences so the they will be shown when the app is opened SharedPreferences.Editor editor = settings.edit(); editor.putFloat("accepted", accepted); editor.putFloat("rejected", rejected); editor.putFloat("immature", immature); editor.putFloat("unexchanged", unexchanged); editor.putFloat("balance", balance); editor.putFloat("paid", paid); //have to make sure that the user's time and date preferences are respected Date date = new Date(); java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); Time time = new Time(); time.setToNow();//w ww. j av a2 s.c om String formattedTime; if (DateFormat.is24HourFormat(context)) { formattedTime = time.format("%k:%M"); } else { formattedTime = time.format("%l:%M %p"); } editor.putString("lastUpdatedTime", dateFormat.format(date) + " " + formattedTime); editor.commit(); //update widget here MainActivity.updateWidget(context); }