Java Utililty Methods String to Time

List of utility methods to do String to Time

Description

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

Method

Datestring2DateTime(String stringDate)
string Date Time
if (stringDate == null) {
    return null;
return getFormat(simple).parse(stringDate);
Datestring2DateTimeByAutoZero(String stringDate)
string Date Time By Auto Zero
if (stringDate == null) {
    return null;
if (stringDate.length() == 11)
    stringDate = stringDate + "00:00:00";
else if (stringDate.length() == 13)
    stringDate = stringDate + ":00:00";
else if (stringDate.length() == 16)
...
CalendarstringToCalendar(String stringTime)
string To Calendar
return stringToCalendar(stringTime, "yyyyMMddHHmmss");
CalendarstringToCalendar(String timeStr)
string To Calendar
Date date = stringToTime(timeStr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
DatestringToTimeDate(String timeStr)
string To Time Date
return formatStrToDate(FORMATO_HORA, timeStr);
DatetoTime(final String dateString)
Tries to interpret a given string as a timestamp This routines assumes that all date parts of a day are present, including time components.
if (dateString == null || dateString.trim().length() < 6)
    return null;
Locale[] locales = { Locale.getDefault(), Locale.UK, Locale.GERMANY };
for (Locale locale : locales) {
    if (!TIME_PATTERNS.containsKey(locale)) {
        List<SimpleDateFormat> patterns = new ArrayList<SimpleDateFormat>();
        for (String pattern : TIME_FORMATS) {
            patterns.add(new SimpleDateFormat(pattern, locale));
...
longtoTime(String display)
Convert between time as a String to milliseconds in a "static" way (to exchange data over the wire, for instance).
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    return sdf.parse(display).getTime();
} catch (ParseException e) {
    return -1;
DatetoTime(String str)
Parses a String as an SQL time.
synchronized (time_format_sql) {
    for (int i = 0; i < time_format_sql.length; ++i) {
        try {
            return time_format_sql[i].parse(str);
        } catch (ParseException e) {
    throw new RuntimeException(dateErrorString("Unable to parse string as a time ", time_format_sql));
...