List of usage examples for java.text SimpleDateFormat clone
@Override
public Object clone()
SimpleDateFormat
. From source file:Main.java
public static void main(String[] argv) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat(); formatter.applyPattern("MMM"); System.out.println(formatter.clone().equals(new SimpleDateFormat())); }
From source file:Main.java
/** * Loops over all the possible date formats and tries to find the right one. * * @param dateValue/*from w w w. j a v a 2s . co m*/ * to parse * @return a valid {@link Date} or null if none of the formats matched. */ public static Date parseDate(String dateValue) { if (dateValue == null) return null; Date date = null; for (final SimpleDateFormat format : FORMATS) { try { final SimpleDateFormat clonedFormat = (SimpleDateFormat) format.clone(); date = clonedFormat.parse(dateValue); break; } catch (ParseException e) { // We loop through this until we found a valid one. //noinspection UnnecessaryContinue continue; } } return date; }
From source file:Currently.java
/** * Ctor: Create a new instance with a formatting string for time stamps. * @param format is a description of the simple date format to use. *///from w ww. ja v a 2 s . c om public Currently(SimpleDateFormat format) { m_formatter = (SimpleDateFormat) format.clone(); }
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Get the current user's date format Will look similar to "mm-dd-yyyy". Depends on user's * locale./* w w w .ja v a 2 s . c o m*/ * * @return a simple date format * @should return a pattern with four y characters in it * @should not allow the returned SimpleDateFormat to be modified * @since 1.5 */ public static SimpleDateFormat getDateFormat(Locale locale) { if (dateFormatCache.containsKey(locale)) { return (SimpleDateFormat) dateFormatCache.get(locale).clone(); } // note that we are using the custom OpenmrsDateFormat class here which prevents erroneous parsing of 2-digit years SimpleDateFormat sdf = new OpenmrsDateFormat( (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale), locale); String pattern = sdf.toPattern(); if (!pattern.contains("yyyy")) { // otherwise, change the pattern to be a four digit year pattern = pattern.replaceFirst("yy", "yyyy"); sdf.applyPattern(pattern); } if (!pattern.contains("MM")) { // change the pattern to be a two digit month pattern = pattern.replaceFirst("M", "MM"); sdf.applyPattern(pattern); } if (!pattern.contains("dd")) { // change the pattern to be a two digit day pattern = pattern.replaceFirst("d", "dd"); sdf.applyPattern(pattern); } dateFormatCache.put(locale, sdf); return (SimpleDateFormat) sdf.clone(); }
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Get the current user's time format Will look similar to "hh:mm a". Depends on user's locale. * /* w w w .ja v a 2 s. c o m*/ * @return a simple time format * @should return a pattern with two h characters in it * @should not allow the returned SimpleDateFormat to be modified * @since 1.9 */ public static SimpleDateFormat getTimeFormat(Locale locale) { if (timeFormatCache.containsKey(locale)) { return (SimpleDateFormat) timeFormatCache.get(locale).clone(); } SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, locale); String pattern = sdf.toPattern(); if (!(pattern.contains("hh") || pattern.contains("HH"))) { // otherwise, change the pattern to be a two digit hour pattern = pattern.replaceFirst("h", "hh").replaceFirst("H", "HH"); sdf.applyPattern(pattern); } timeFormatCache.put(locale, sdf); return (SimpleDateFormat) sdf.clone(); }
From source file:org.zuinnote.hadoop.office.format.common.converter.ExcelConverterSimpleSpreadSheetCellDAO.java
/*** * Create a new converter// w w w .j a v a 2 s. co m * * @param dateFormat format of the dates in the Excel. This format is cloned in the constructor to avoid inferences. * @param decimalFormat format of the decimals in the Excel. This format is cloned in the constructor to avoid inferences. * @param dateTimeFormat format of date time cells in the Excel. This format is cloned in the constructor to avoid inferences. */ public ExcelConverterSimpleSpreadSheetCellDAO(SimpleDateFormat dateFormat, DecimalFormat decimalFormat, SimpleDateFormat dateTimeFormat) { this.schemaRow = new ArrayList<>(); this.dateFormat = (SimpleDateFormat) dateFormat.clone(); this.decimalFormat = (DecimalFormat) decimalFormat.clone(); this.decimalFormat.setParseBigDecimal(true); if (dateTimeFormat != null) { this.dateTimeFormat = (SimpleDateFormat) dateTimeFormat.clone(); } }