Java Code Examples for java.text.SimpleDateFormat#clone()

The following examples show how to use java.text.SimpleDateFormat#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExcelConverterSimpleSpreadSheetCellDAO.java    From hadoopoffice with Apache License 2.0 5 votes vote down vote up
/***
 * Create a new converter
 * 
 * @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();
	}
}
 
Example 2
Source File: SimpleDateFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_equalsLjava_lang_Object() {
    // Test for method boolean
    // java.text.SimpleDateFormat.equals(java.lang.Object)
    SimpleDateFormat format = (SimpleDateFormat) DateFormat.getInstance();
    SimpleDateFormat clone = (SimpleDateFormat) format.clone();
    assertTrue("clone not equal", format.equals(clone));
    format.format(new Date());
    assertTrue("not equal after format", format.equals(clone));
}
 
Example 3
Source File: SimpleDateFormatTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_hashCode() {
    SimpleDateFormat format = (SimpleDateFormat) DateFormat.getInstance();
    SimpleDateFormat clone = (SimpleDateFormat) format.clone();
    assertTrue("clone has not equal hash code", clone.hashCode() == format.hashCode());
    format.format(new Date());
    assertTrue("clone has not equal hash code after format",
            clone.hashCode() == format.hashCode());
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.ENGLISH);
    symbols.setEras(new String[] { "Before", "After" });
    SimpleDateFormat format2 = new SimpleDateFormat("y'y'yy", symbols);
    assertFalse("objects has equal hash code", format2.hashCode() == format.hashCode());
}
 
Example 4
Source File: DatesTest.java    From howsun-javaee-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = sdf1;
	SimpleDateFormat sdf3 = (SimpleDateFormat)sdf1.clone();
	System.out.println(sdf1);
	System.out.println(sdf2);
	System.out.println(sdf3);
	System.out.println(sdf1.toLocalizedPattern());
	System.out.println(sdf1.toPattern());

}