List of usage examples for java.text SimpleDateFormat toPattern
public String toPattern()
From source file:com.adaptris.core.services.jdbc.TimestampStatementParameter.java
public TimestampStatementParameter(String query, QueryType type, Boolean nullConvert, String name, SimpleDateFormat format) { super(query, type, nullConvert, name); setDateFormat(format.toPattern()); }
From source file:org.openmrs.web.taglib.TimePatternTag.java
/** * Does the actual working of printing the time pattern * * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() *//*from ww w.java 2 s .c o m*/ @Override public int doStartTag() { SimpleDateFormat dateFormat = Context.getTimeFormat(); try { String pattern; if ((localize != null) && "false".equals(localize)) { pattern = dateFormat.toPattern().toLowerCase(); } else { pattern = dateFormat.toLocalizedPattern(); } if (null != format && format.equals("jquery")) { pattern = pattern.toLowerCase().replaceAll("a", "TT"); } pageContext.getOut().write(pattern); } catch (Exception e) { log.error("error getting date pattern", e); } return SKIP_BODY; }
From source file:surrey.csv.profile.expression.DateExpressionEvaluator.java
@Override public String evaluate(JSONObject exp, Map<String, String> valueMap) throws JSONException { Date date = new Date(); if (exp.has("value")) { String value = valueMap.get(exp.getString("value")); SimpleDateFormat inDf = new SimpleDateFormat(exp.getString("in")); try {// w ww .ja va 2 s .com date = inDf.parse(value); } catch (ParseException e) { throw new JSONException( "Failed to convert value: " + value + " into a date using pattern: " + exp.getString("in")); } } if (exp.has("op")) { JSONObject op = exp.getJSONObject("op"); String opName = JSONObject.getNames(op)[0]; op = op.getJSONObject(opName); String field = JSONObject.getNames(op)[0]; int amount = op.getInt(field); int calField = Calendar.DAY_OF_MONTH; if (field.endsWith("s")) { field = field.substring(0, field.length() - 1); } if (field.equals("month")) { calField = Calendar.MONTH; } else if (field.equals("year")) { calField = Calendar.YEAR; } Calendar cal = Calendar.getInstance(); cal.setTime(date); if (opName.equals("add")) { cal.add(calField, amount); } else { cal.add(calField, -amount); } date = cal.getTime(); } SimpleDateFormat df = new SimpleDateFormat(); if (exp.has("out")) { df.applyPattern(exp.getString("out")); } return df.toPattern() + PATTERN_SEPARATOR + df.format(date); }
From source file:org.openmrs.web.taglib.DatePatternTag.java
/** * Does the actual working of printing the date pattern * /* ww w. ja v a 2 s . co m*/ * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() */ @Override public int doStartTag() { SimpleDateFormat dateFormat = Context.getDateFormat(); try { String pattern = dateFormat.toLocalizedPattern().toLowerCase(); if ((localize != null) && "false".equals(localize)) { pattern = dateFormat.toPattern().toLowerCase(); } pageContext.getOut().write(pattern); } catch (Exception e) { log.error("error getting date pattern", e); } return SKIP_BODY; }
From source file:org.openmrs.web.taglib.DateTimePatternTag.java
/** * Does the actual working of printing the datetime pattern * //from w ww . j ava2 s. c o m * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() */ @Override public int doStartTag() { SimpleDateFormat dateTimeFormat = Context.getDateTimeFormat(); try { String pattern = dateTimeFormat.toLocalizedPattern().toLowerCase(); if ((localize != null) && "false".equals(localize)) { pattern = dateTimeFormat.toPattern().toLowerCase(); } pageContext.getOut().write(pattern); } catch (Exception e) { log.error("error getting datetime pattern", e); } return SKIP_BODY; }
From source file:com.ponysdk.ui.server.basic.PDateBox.java
public void setDateFormat(final SimpleDateFormat dateFormat) { this.dateFormat = dateFormat; final Update update = new Update(getID()); update.put(PROPERTY.DATE_FORMAT_PATTERN, dateFormat.toPattern()); Txn.get().getTxnContext().save(update); }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.converter.NullAwareDateFilterValueConverter.java
public Date parseDate(String value, SimpleDateFormat dateFormat) { if (StringUtils.isEmpty(value)) { return null; }/*from w w w. j av a 2 s . co m*/ try { return dateFormat.parse(value); } catch (ParseException e) { throw new RuntimeException( "Error while converting '" + value + "' into Date using pattern " + dateFormat.toPattern(), e); } }
From source file:org.openmrs.module.sync.serialization.TimestampNormalizer.java
@Override public Object fromString(Class clazz, String s) { if (StringUtils.isBlank(s)) return null; if ("java.util.Date".equals(clazz.getName()) || "java.sql.Timestamp".equals(clazz.getName())) { //result = d.toString() + ' ' + t.toString(); Date result = null;/*from w w w .j a v a2 s . c o m*/ SimpleDateFormat dfm = new SimpleDateFormat(DATETIME_MASK); try { result = dfm.parse(s.trim()); } catch (ParseException e) { log.debug("DateParsingException trying to turn " + s + " into a date with pattern: " + dfm.toPattern() + " , so retrying with backup mask"); try { dfm = new SimpleDateFormat(DATETIME_MASK_BACKUP); result = dfm.parse(s.trim()); } catch (ParseException pee) { log.debug("Still getting DateParsingException trying to turn " + s + " into a date using backup pattern: " + dfm.toPattern()); } } return result; } return null; }
From source file:BaseProperties.java
/** * Set <code>DateFormat</code> object. */// ww w .j ava 2s. c om public void setProperty(final String key, final SimpleDateFormat val) { setProperty(key, val.toPattern()); }
From source file:edu.ku.brc.specify.tests.PreferenceTest.java
/** * Tests the Date formating//from w w w.j a v a 2s. c o m */ public void testSimpleDateFormat() { FastDateFormat fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.SHORT); SimpleDateFormat df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM); df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); fastDateFormat = FastDateFormat.getDateInstance(FastDateFormat.LONG); df = new SimpleDateFormat(fastDateFormat.getPattern()); log.info(df.toPattern()); log.info(df.format(new Date())); }