List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance()
From source file:org.openadaptor.auxil.expression.function.DateParseFn.java
public DateParseFn() { super(DateParseFn.NAME, 2); df = DateFormat.getDateTimeInstance(); if (df instanceof SimpleDateFormat) { sdf = (SimpleDateFormat) df; } else {/*from w ww . j a v a2 s . com*/ sdf = null; DateParseFn.log.warn("DateFormat is not a SimpleDateFormat - format strings will be ignored"); } }
From source file:org.openadaptor.auxil.expression.function.FormatFn.java
public FormatFn() { super(NAME, 2); df = DateFormat.getDateTimeInstance(); if (df instanceof SimpleDateFormat) { sdf = (SimpleDateFormat) df; } else {/*from ww w.j av a2 s . co m*/ sdf = null; log.warn("DateFormat is not a SimpleDateFormat - format strings will be ignored"); } }
From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java
public static String format(String type, String value, JspContext jspContext) { if (StringUtils.isEmpty(value)) { return value; } else if ("date".equals(type) || "timestamp".equals(type) || "hour".equals(type)) { DateFormat dateFormat = DateFormat.getDateTimeInstance(); if ("timestamp".equals(type)) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale(jspContext)); } else if ("date".equals(type)) { dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale(jspContext)); } else if ("hour".equals(type)) { dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale(jspContext)); }// w w w.j a va 2 s .c o m List<String> patterns = new ArrayList<>(); patterns.add("yyyy-MM-dd HH:mm:ss"); patterns.add("yyyy-MM-dd"); patterns.add("E MMM dd HH:mm:ss zzz yyyy"); for (String pattern : patterns) { try { return dateFormat.format(new SimpleDateFormat(pattern, Locale.ENGLISH).parse(value)); } catch (ParseException pe) { //Try another format } } return value; } else if ("currency".equals(type)) { DecimalFormat nf = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(locale(jspContext))); return nf.format(new Double(value)); } else if ("cep".equals(type)) { return String.format("%08d", Long.valueOf(value)).replaceAll("^([0-9]{5})([0-9]{3})$", "$1-$2"); } else if ("cpf".equals(type)) { return String.format("%011d", Long.valueOf(value)) .replaceAll("^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})$", "$1.$2.$3-$4"); } else if ("cnpj".equals(type)) { return String.format("%014d", Long.valueOf(value)) .replaceAll("^([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})$", "$1.$2.$3/$4-$5"); } else if ("tel".equals(type)) { return String.format("%010d", Long.valueOf(value)).replaceAll("^([0-9]{2})([0-9]{4,5})([0-9]{4})$", "($1) $2-$3"); } return value; }
From source file:com.anthonykeane.speedzone.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *//* www . j a v a 2 s. c o m*/ @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(ActivityUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Log the update logActivityRecognitionResult(result); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence percentage for the most probable activity int confidence = mostProbableActivity.getConfidence(); // Get the type of activity int activityType = mostProbableActivity.getType(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type SharedPreferences.Editor editor = mPrefs.edit(); editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } else if (activityChanged(activityType) // The activity has changed from the previous activity && (confidence >= 80)) // The confidence level for the current activity is > 50% { switch (activityType) { case DetectedActivity.IN_VEHICLE: Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); callIntent.setClass(getApplicationContext(), MainActivity.class); // todo callIntent.putExtra("bZoneError",bZoneError); startActivity(callIntent); break; //case DetectedActivity.STILL: //case DetectedActivity.ON_BICYCLE: case DetectedActivity.ON_FOOT: //sendNotification(); break; } } } }
From source file:com.example.android.activityrecognition.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *///from w w w.j av a 2s. com @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(ActivityUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Log the update logActivityRecognitionResult(result); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence percentage for the most probable activity int confidence = mostProbableActivity.getConfidence(); // Get the type of activity int activityType = mostProbableActivity.getType(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type Editor editor = mPrefs.edit(); editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } else if ( // If the current type is "moving" isMoving(activityType) && // The activity has changed from the previous activity activityChanged(activityType) // The confidence level for the current activity is > 50% && (confidence >= 50)) { // Notify the user sendNotification(); } } }
From source file:com.callrecorder.android.RecordingsAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { View rowView = convertView;//from w w w . ja v a 2s . c om if (rowView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.record_row, parent, false); } final TextView titleView = (TextView) rowView.findViewById(R.id.recording_title); final TextView dateView = (TextView) rowView.findViewById(R.id.recording_date); final TextView numberView = (TextView) rowView.findViewById(R.id.recording_number); Recording entry = list.get(position); String phoneNumber = entry.getPhoneNumber(); if (phoneNumber.matches("^[\\d]+$")) { //noinspection deprecation phoneNumber = PhoneNumberUtils.formatNumber(phoneNumber); } else { phoneNumber = context.getString(R.string.withheld_number); } dateView.setText(DateFormat.getDateTimeInstance().format(entry.getDate())); titleView.setText(entry.getUserName()); numberView.setText(phoneNumber); return rowView; }
From source file:com.twinsoft.convertigo.beans.statements.CookiesAddStatement.java
protected void addCookie(HttpState httpState, String cook) { String name = ""; String domain = ""; String path = ""; String value = ""; boolean secure = false; Date expires = new Date(Long.MAX_VALUE); String[] fields = cook.split(";"); for (int i = 0; i < fields.length; i++) { String[] half = fields[i].trim().split("="); if (half.length == 2) { if (fields[i].startsWith("$")) { if (half[0].equals("$Domain")) domain = half[1];/*from w ww. ja v a2s. co m*/ else if (half[0].equals("$Path")) path = half[1]; else if (half[0].equals("$Secure")) secure = Boolean.getBoolean(half[1]); else if (half[0].equals("$Date")) try { expires = DateFormat.getDateTimeInstance().parse(half[1]); } catch (ParseException e) { } } else { name = half[0]; value = half[1]; } } } Cookie cookie = null; try { cookie = new Cookie(domain, name, value, path, expires, secure); if (cookie != null) httpState.addCookie(cookie); } catch (Exception e) { Engine.logBeans.debug("(CookiesAdd) failed to parse those cookies : " + cook); } }
From source file:org.isoron.uhabits.helpers.ReminderHelper.java
public static void createReminderAlarm(Context context, Habit habit, @Nullable Long reminderTime) { if (!habit.hasReminder()) return;//from w w w .j a va 2 s. c o m if (reminderTime == null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); //noinspection ConstantConditions calendar.set(Calendar.HOUR_OF_DAY, habit.reminderHour); //noinspection ConstantConditions calendar.set(Calendar.MINUTE, habit.reminderMin); calendar.set(Calendar.SECOND, 0); reminderTime = calendar.getTimeInMillis(); if (System.currentTimeMillis() > reminderTime) reminderTime += AlarmManager.INTERVAL_DAY; } long timestamp = DateHelper.getStartOfDay(DateHelper.toLocalTime(reminderTime)); Uri uri = habit.getUri(); Intent alarmIntent = new Intent(context, HabitBroadcastReceiver.class); alarmIntent.setAction(HabitBroadcastReceiver.ACTION_SHOW_REMINDER); alarmIntent.setData(uri); alarmIntent.putExtra("timestamp", timestamp); alarmIntent.putExtra("reminderTime", reminderTime); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, ((int) (habit.getId() % Integer.MAX_VALUE)) + 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Build.VERSION.SDK_INT >= 23) manager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); else if (Build.VERSION.SDK_INT >= 19) manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); else manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent); String name = habit.name.substring(0, Math.min(3, habit.name.length())); Log.d("ReminderHelper", String.format("Setting alarm (%s): %s", DateFormat.getDateTimeInstance().format(new Date(reminderTime)), name)); }
From source file:com.exquance.jenkins.plugins.HarbormasterTrigger.java
/** * Called when a POST is made.//from w w w. j a va 2s . c om */ public void onPost(String triggeredByUser) { final String pushBy = triggeredByUser; getDescriptor().queue.execute(new Runnable() { private boolean runPolling() { try { StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); boolean result = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job).poll(listener) .hasChanges(); logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); if (result) logger.println("Changes found"); else logger.println("No changes"); return result; } catch (Error e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } catch (RuntimeException e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } finally { listener.close(); } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); } return false; } public void run() { if (runPolling()) { String name = " #" + job.getNextBuildNumber(); HarbormasterPushCause cause; try { cause = new HarbormasterPushCause(getLogFile(), pushBy); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to parse the polling log", e); cause = new HarbormasterPushCause(pushBy); } ParameterizedJobMixIn pJob = new ParameterizedJobMixIn() { @Override protected Job asJob() { return job; } }; if (pJob.scheduleBuild(cause)) { LOGGER.info("SCM changes detected in " + job.getName() + ". Triggering " + name); } else { LOGGER.info("SCM changes detected in " + job.getName() + ". Job is already in the queue"); } } } }); }
From source file:com.emlago.sensorex.services.activity_recognition.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *///from www.j av a 2s .co m @Override protected void onHandleIntent(Intent intent) { Log.d("ActivityRecognition", "onHandleIntent"); // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(ActivityUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Log the update logActivityRecognitionResult(result); //// post activity to the bus postActivityEvent(result.getMostProbableActivity()); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence percentage for the most probable activity int confidence = mostProbableActivity.getConfidence(); // Get the type of activity int activityType = mostProbableActivity.getType(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type Editor editor = mPrefs.edit(); editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } else if ( // If the current type is "moving" isMoving(activityType) && // The activity has changed from the previous activity activityChanged(activityType) // The confidence level for the current activity is > 50% && (confidence >= 50)) { // Notify the user sendNotification(); } } }