Java Utililty Methods Parse Date

List of utility methods to do Parse Date

Description

The list of methods to do Parse Date are organized into topic(s).

Method

DateparseDateTime(String d, String t)
parse Date Time
Calendar cal = new GregorianCalendar();
Date now = new Date();
cal.setTime(now);
int YY = Integer.parseInt(d.substring(4));
int MM = Integer.parseInt(d.substring(0, 2)) - 1;
int DD = Integer.parseInt(d.substring(2, 4));
int hh = Integer.parseInt(t.substring(0, 2));
int mm = Integer.parseInt(t.substring(2, 4));
...
DateparseDateTime(String date)
Description goes here.
if (date == null) {
    throw new NullPointerException("Provided date is null");
Date parsedDate = null;
DateFormat dateFormat = new SimpleDateFormat(DATE_TIME_PATTERN, Locale.ENGLISH);
dateFormat.setTimeZone(UTC_TIME_ZONE);
try {
    parsedDate = dateFormat.parse(date);
...
java.util.DateparseDateTime(String date, String format, String locale, String timeZone)
Parses a date using a format string.
SimpleDateFormat dateFormat = getDateFormat(format, locale, timeZone);
try {
    synchronized (dateFormat) {
        return dateFormat.parse(date);
} catch (Exception e) {
    throw new RuntimeException("PARSE_ERROR:" + date, e);
longparseDateTime(String date, String time)
parse Date Time
long long0 = 0l;
String maxTime = date + " " + time + ":00:000";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
try {
    Date day = sdf.parse(maxTime);
    return day.getTime();
} catch (ParseException e) {
    e.printStackTrace();
...
DateparseDateTime(String dateTime)
return a date from a string
Calendar time = Calendar.getInstance();
time.set(0, 0, 0, 0, 0);
String rest = "";
for (String part : dateTime.split("\\s")) {
    if (part.contains(":")) {
        time = parseTime(time, part);
    } else {
        rest += part + " ";
...
DateparseDateTime(String dateTimeStr)
parse Date Time
if (dateTimeStr.contains("00:00T")) {
    dateTimeStr = dateTimeStr.replaceFirst("00:00T", "");
try {
    if (isValidDateTimeString(dateTimeStr)) {
        return (new SimpleDateFormat(DATETIME_FORMAT).parse(dateTimeStr));
    } else if (isValidDateString(dateTimeStr)) {
        return (new SimpleDateFormat(DATETIME_FORMAT).parse(dateTimeStr.concat("T00:00:00")));
...
DateparseDateTime(String dateTimeString)
parse Date Time
Date d = null;
try {
    d = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a").parse(dateTimeString);
} catch (ParseException e) {
    try {
        d = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(dateTimeString);
    } catch (ParseException parseException) {
        parseException.printStackTrace();
...
java.util.DateparseDateTime(String dateTimeString)
parse Date Time
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
if (df instanceof SimpleDateFormat) {
    SimpleDateFormat sdf = (SimpleDateFormat) df;
    sdf.applyPattern(sdf.toPattern() + " HH:mm:ss");
    df = sdf;
return df.parse(dateTimeString);
StringparseDateTime(String dateTimeString, String[] validFormats, String outputFormat)
parse Date Time
for (int i = 0; i < validFormats.length; i++) {
    SimpleDateFormat format = new SimpleDateFormat(validFormats[i]);
    DateFormat df = new SimpleDateFormat(outputFormat);
    format.setLenient(false);
    try {
        Date temp = format.parse(dateTimeString);
        if (temp != null) {
            return df.format(temp);
...
DateparseDateTime(String format, String dateStr)
Parses specified date string according to format.
if ((format == null) || (dateStr == null)) {
    return null;
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setLenient(false);
return formatter.parse(dateStr);