@Override public void onPositiveActionClicked(DialogFragment fragment) { TimePickerDialog dialog = (TimePickerDialog)fragment.getDialog(); Toast.makeText(mActivity, "Time is " + dialog.getFormattedTime(SimpleDateFormat.getTimeInstance()), Toast.LENGTH_SHORT).show(); super.onPositiveActionClicked(fragment); }
private static String formatDate(FldSimpleModel model, String format, Date date, String lang) { DateFormat dateFormat = null; if ((format != null) && (format.length() > 0)) { SimpleDateFormat simpleDateFormat = getSimpleDateFormat(lang); simpleDateFormat.applyPattern(convertDatePattern(format)); dateFormat = simpleDateFormat; } else { dateFormat = (model.getFldName().indexOf("DATE") > -1 ? SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT) : SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT)); } return dateFormat.format(date); }
@SuppressLint("SimpleDateFormat") @Override public boolean isValid(EditText et) { if (TextUtils.isEmpty(et.getText())) return true; String value = et.getText().toString(); for (String _format : formats) { DateFormat format; if ("DefaultDate".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getDateInstance(); } else if ("DefaultTime".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getTimeInstance(); } else if ("DefaultDateTime".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getDateTimeInstance(); } else { format = new SimpleDateFormat(_format); } Date date = null; try { date = format.parse(value); } catch (ParseException e) { return false; } if (date != null) { return true; } } return false; }
/** * Creates a date spinner using locale default as the format string. */ public DateSpinner() { this(((SimpleDateFormat) SimpleDateFormat.getTimeInstance(SimpleDateFormat.DEFAULT, Locale.getDefault())).toPattern()); }
private static String getDateTime() { return SimpleDateFormat.getTimeInstance().format(new Date()); }
private static String getDateTime() { return SimpleDateFormat.getTimeInstance().format(new Date()); }
/** * Format the string according to the parameter isDate * @param isDate: date formating or time formating * @return */ public String toString(boolean isDate) { GregorianCalendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth, startTimeOfDay, startMinute); calendar.setTimeZone(TimeZone.getTimeZone("GMT0")); DateFormat instance = isDate ? SimpleDateFormat.getDateInstance() : SimpleDateFormat.getTimeInstance(DateFormat.SHORT); instance.setTimeZone(TimeZone.getTimeZone("GMT0")); return instance.format(calendar.getTime()); }
private void initDateTimeFormat() { simpleTimeFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT); simpleDateFormat = SimpleDateFormat.getDateInstance(); }
private String formatDate(long time) { Calendar today = Calendar.getInstance(); today.clear(Calendar.HOUR_OF_DAY); today.clear(Calendar.MINUTE); today.clear(Calendar.SECOND); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); DateFormat format; if (cal.after(today)) { format = SimpleDateFormat.getTimeInstance(); } else { format = SimpleDateFormat.getDateTimeInstance(); } return format.format(new Date(time)); } }
public static String dateToString(Date date, int format) { switch (format) { case DATE: return new SimpleDateFormat("MM/d").format(date); case TIME: return SimpleDateFormat.getTimeInstance(DateFormat.SHORT).format(date); case MEDIUM: return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(date); default: return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(date); } }
protected String format(Date nextExecution) { long current = System.currentTimeMillis(); //if it's less than 15 hours away only show the time if(nextExecution.getTime()-current<TimeUnit.HOURS.toMillis(23)) return SimpleDateFormat.getTimeInstance(DateFormat.SHORT,getLocale()).format(nextExecution); return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT,SimpleDateFormat.SHORT,getLocale()).format(nextExecution); }
/** * Gets currently active time format. Value is either TimeFormat.Format12H * or TimeFormat.Format24H. * * @return TimeFormat Format for the time. */ public TimeFormat getTimeFormat() { if (currentTimeFormat == null) { SimpleDateFormat f; if (getLocale() == null) { f = (SimpleDateFormat) SimpleDateFormat .getTimeInstance(SimpleDateFormat.SHORT); } else { f = (SimpleDateFormat) SimpleDateFormat .getTimeInstance(SimpleDateFormat.SHORT, getLocale()); } String p = f.toPattern(); if (p.indexOf("HH") != -1 || p.indexOf("H") != -1) { return TimeFormat.Format24H; } return TimeFormat.Format12H; } return currentTimeFormat; }
public static String format(Date date, String formatPattern, Locale locale) { if (date == null) { return StringUtils.EMPTY; } if (formatPattern == null) { formatPattern = FORMAT_DEFAULTPATTERN; } if (FORMAT_DATE_SHORT.equals(formatPattern)) { return SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, locale).format(date); } else if (FORMAT_DATE_MEDIUM.equals(formatPattern)) { return SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM, locale).format(date); } else if (FORMAT_DATE_LONG.equals(formatPattern)) { return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG, locale).format(date); } else if (FORMAT_TIME_SHORT.equals(formatPattern)) { return SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT, locale).format(date); } else if (FORMAT_TIME_MEDIUM.equals(formatPattern)) { return SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, locale).format(date); } else if (FORMAT_TIME_LONG.equals(formatPattern)) { return SimpleDateFormat.getTimeInstance(SimpleDateFormat.LONG, locale).format(date); } else if (FORMAT_DATETIME_SHORT.equals(formatPattern)) { return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, locale).format(date); } else if (FORMAT_DATETIME_MEDIUM.equals(formatPattern)) { return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM, locale).format(date); } else if (FORMAT_DATETIME_LONG.equals(formatPattern)) { return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG, locale).format(date); } else { return DateFormatUtils.format(date, formatPattern, locale); } }
private static String formatDate(FldSimpleModel model, String format, Date date, String lang) { DateFormat dateFormat = null; if ((format != null) && (format.length() > 0)) { SimpleDateFormat simpleDateFormat = getSimpleDateFormat(lang); simpleDateFormat.applyPattern(convertDatePattern(format)); dateFormat = simpleDateFormat; } else { dateFormat = (model.getFldName().indexOf("DATE") > -1 ? SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT) : SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT)); } return dateFormat.format(date); }
/** * Set the time on a windows system * * @param calendar the time to set */ private void setWindowsTime( Calendar calendar ) throws Exception { // we are using the default date format and the system specific time format // set the date String dateArguments = String.format("%1$02d-%2$02d-%3$02d", calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR)); LocalProcessExecutor processExecutor = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, "cmd /c date " + dateArguments); processExecutor.execute(); // set the time String timeArguments = SimpleDateFormat.getTimeInstance().format(calendar.getTime()); processExecutor = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, "cmd /c time " + timeArguments); processExecutor.execute(); }
@Override public void handle(SimulationEvent event) { String taskId = (String) event.getProperty("task"); // fulfill variables @SuppressWarnings("unchecked") Map<String, Object> variables = (Map<String, Object>) event.getProperty("variables"); SimulationRunContext.getTaskService().complete( taskId, variables ); log.debug( SimpleDateFormat.getTimeInstance().format( new Date(event.getSimulationTime())) +": completed taskId "+ taskId + " variable update [" + variables +"]"); }
public Formatter getTimeFormatter(Style style) { return new DateFormatter(SimpleDateFormat.getTimeInstance(style.shortValue(), getLocale())); }
@Override public void handle(SimulationEvent event) { TaskEntity task = (TaskEntity) event.getProperty(); if (claimTask(task)) { // create complete task event Map<String, Object> props = new HashMap<String, Object>(); props.put( "task", task.getId()); Map<String, Object> variables = new HashMap<String, Object>(); long userTaskDelta = userTaskExecutor.simulateTaskExecution(task, variables); props.put( "variables", variables); SimulationEvent completeEvent = new SimulationEvent( ClockUtil.getCurrentTime().getTime() + userTaskDelta, SimulationEvent.TYPE_TASK_COMPLETE, props); // schedule complete task event SimulationRunContext.getEventCalendar().addEvent( completeEvent); log.debug( SimpleDateFormat.getTimeInstance().format( new Date(event.getSimulationTime())) +": claimed {}, name: {}, assignee: {}", task, task.getName(), task.getAssignee()); } }
@Override public void handle(SimulationEvent event) { TaskEntity task = (TaskEntity) event.getProperty(); SimulationRunContext.getTaskService().claim(task.getId(), DEFAULT_USER); task.setAssignee( DEFAULT_USER ); // create complete task event Map<String, Object> props = new HashMap<String, Object>(); props.put( "task", task.getId()); Map<String, Object> variables = new HashMap<String, Object>(); long userTaskDelta = userTaskExecutor.simulateTaskExecution(task, variables); props.put( "variables", variables); SimulationEvent completeEvent = new SimulationEvent( ClockUtil.getCurrentTime().getTime() + userTaskDelta, SimulationEvent.TYPE_TASK_COMPLETE, props); // schedule complete task event SimulationRunContext.getEventCalendar().addEvent( completeEvent); log.debug( SimpleDateFormat.getTimeInstance().format( new Date(event.getSimulationTime())) +": claimed {}, name: {}, assignee: {}", task, task.getName(), task.getAssignee()); }
public ExporterFormatter(Locale locale) { this.locale = locale; this.dateTimeFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); this.dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, locale); this.timeFormat = (SimpleDateFormat) SimpleDateFormat.getTimeInstance(DateFormat.SHORT, locale); this.decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale); this.integerFormat = (DecimalFormat) DecimalFormat.getIntegerInstance(locale); this.currencyFormat = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale == Locale.ENGLISH ? Locale.US : locale); this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormat.toPattern()); this.cellDateFormat = DateFormatConverter.convert(locale, dateFormat.toPattern()); this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormat.toPattern()); this.cellDecimalFormat = DateFormatConverter.convert(locale, decimalFormat.toPattern()); this.cellIntegerFormat = DateFormatConverter.convert(locale, integerFormat.toPattern()); this.cellCurrencyFormat = DateFormatConverter.convert(locale, getCurrencyFormatString()); }