
zone.cogni.libs.core.utils.DataUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cogni-libs Show documentation
Show all versions of cogni-libs Show documentation
Library for Semantic Development
package zone.cogni.libs.core.utils;
import java.util.Date;
import static java.util.Objects.requireNonNull;
/**
*/
public class DataUtils {
public static Date tryParse(String dateString) {
Date date = DateFormats.parseXsdDateTimeFormat(dateString);
if (date == null) date = DateFormats.parse(dateString, DateFormats.Format.JAVAFULLXMLDATETIME);
if (date == null) date = DateFormats.parse(dateString, DateFormats.Format.FULLXMLDATETIME);
if (date == null) date = DateFormats.parse(dateString, DateFormats.Format.XMLDATETIME);
if (date == null) date = DateFormats.parse(dateString, DateFormats.Format.DATE);
return date;
}
public static String parseDateAsString(String dateAsString) {
Date parsedDate = tryParse(dateAsString);
requireNonNull(parsedDate, () -> "Illegal date format found '" + dateAsString + "'");
return DateFormats.formatXsdDateTimeFormat(parsedDate);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy