Java Utililty Methods Parse Time

List of utility methods to do Parse Time

Description

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

Method

DateparseTime(String text)
parse Time
if (text == null)
    return null;
Matcher matcher = TZ_REGEX.matcher(text);
TimeZone timeZone = null;
if (matcher.find()) {
    String tzCode = "GMT" + matcher.group(1) + matcher.group(2); 
    timeZone = TimeZone.getTimeZone(tzCode);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
if (timeZone != null) {
    formatter.setTimeZone(timeZone);
try {
    Date result = formatter.parse(text);
    return result;
} catch (ParseException e) {
    return null;
DateparseTime(String time)
parse Time
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy h.mm a");
Date temp = dateFormatter.parse(time, new ParsePosition(0));
if (temp == null) {
    dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
    temp = dateFormatter.parse(time, new ParsePosition(0));
    return temp;
return temp;
...
DateparseTime(String time)
Returns Date from specified String time representation.
if (datePattern == null) {
    datePattern = Pattern.compile("([0-9]{4})-([0-9]{2})-([0-9]{2}).([0-9]{2}):([0-9]{2}):([0-9]{2})");
Matcher matcher = datePattern.matcher(time);
if (!matcher.matches()) {
    throw new ParseException("Bad date format [" + time + "]", 0);
try {
...
StringparseTime(String time, String formatStrBefore, String formatStrAfter)
parse Time
SimpleDateFormat bfSp = new SimpleDateFormat(formatStrBefore);
SimpleDateFormat afSp = new SimpleDateFormat(formatStrAfter);
return afSp.format(bfSp.parse(time));
CalendarparseTime(String timestring)
Returns a calendar for the given time string.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = sdf.parse(timestring);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
return cal;
longparseTime(String timeString, TimeZone timeZone)
Parses time string into epoch milliseconds
DateFormat dateFormat;
if (timeString.contains(".")) {
    dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
} else {
    dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
dateFormat.setTimeZone(timeZone);
Date date = dateFormat.parse(timeString);
...
DateparseTime(String token)
parse Time
Date retval = null;
try {
    retval = _TIME_FORMAT.parse(token);
} catch (final Exception e) {
    retval = null;
return retval;
DateparseTimeConfiguration(String time)
parse Time Configuration
try {
    return TIME_FORMAT_WITHOUT_SECONDS_WITH_TIMEZONE.parse(time);
} catch (ParseException ex) {
    return TIME_FORMAT_WITHOUT_SECONDS.parse(time);
intparseTimeSpec(String[] spec)
parse Time Spec
if (spec == null || spec.length < 1 || spec.length > 2)
    return -1;
if (spec.length == 1 && isInt(spec[0]))
    return Integer.valueOf(spec[0]);
if (!spec[0].contains(":") && !spec[0].contains("."))
    if (spec.length == 2) {
        if (!isInt(spec[0]))
            return -1;
...
DateparseTimeStr(String timeStr)
parse Time Str
try {
    return new SimpleDateFormat("yyyy MM dd HH:mm:ss").parse(timeStr);
} catch (java.text.ParseException e) {
    throw new Error("wrong time format '" + timeStr + "'");