
org.ow2.bonita.util.DateUtil Maven / Gradle / Ivy
package org.ow2.bonita.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public abstract class DateUtil {
private DateUtil() {
}
public static final SimpleDateFormat DATE_FORMAT_1 = new SimpleDateFormat("yyyy/MM/dd/HH/mm/ss/SSS");
public static final SimpleDateFormat DATE_FORMAT_2 = new SimpleDateFormat("yyyy/MM/dd/HH/mm/ss");
// ISO-8601 requires the T between date and time.
public static final SimpleDateFormat ISO_8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public static Date parseDate(final String formattedDate) {
Date result;
try {
result = DateUtil.DATE_FORMAT_1.parse(formattedDate);
} catch (final ParseException e1) {
try {
result = DateUtil.DATE_FORMAT_2.parse(formattedDate);
} catch (final ParseException e2) {
try {
result = DateUtil.ISO_8601_FORMAT.parse(formattedDate);
} catch (final ParseException e3) {
String message = ExceptionManager.getInstance().getFullMessage("bu_DU_1",
formattedDate, DateUtil.DATE_FORMAT_2.toPattern(), DateUtil.DATE_FORMAT_1.toPattern(), DateUtil.ISO_8601_FORMAT.toPattern());
throw new IllegalArgumentException(message);
}
}
}
return result;
}
public static String format(final Date date) {
return DateUtil.ISO_8601_FORMAT.format(date);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy