Java Utililty Methods Date from String

List of utility methods to do Date from String

Description

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

Method

DategetDateFromStartTime(String startTime)
get Date From Start Time
int splitIndex = startTime.indexOf(':');
int hourOfDay = 0, minutes = 0;
try {
    hourOfDay = Integer.parseInt(startTime.substring(0, splitIndex));
    minutes = Integer.parseInt(startTime.substring(splitIndex + 1));
} catch (NumberFormatException e) {
Calendar cal = Calendar.getInstance();
...
longgetDateFromString(String s)
get Date From String
int day, month, year;
int i = s.indexOf('/');
if (i < 0)
    return 0;
try {
    day = Integer.parseInt(s.substring(0, i));
} catch (NumberFormatException e) {
    return 0;
...
DategetDateFromString(String strDate, String strTime)
get Date From String
Calendar cal = Calendar.getInstance();
String[] arrDate = strDate.split("-");
String[] arrTime = strTime.split("[:-]");
cal.set(Integer.parseInt(arrDate[0]), Integer.parseInt(arrDate[1]) - 1, Integer.parseInt(arrDate[2]),
        Integer.parseInt(arrTime[0]), Integer.parseInt(arrTime[1]), Integer.parseInt(arrTime[1]));
return cal.getTime();
CalendargetDateFromString(String stringDate)
get Date From String
Calendar calendar = Calendar.getInstance();
calendar.set(new Integer(stringDate.substring(0, 4)), new Integer(stringDate.substring(4, 6)) - 1,
        new Integer(stringDate.substring(6, 8)), 0, 0, 0);
return calendar;
DategetDateFromTime(long millisSinceMidnight)
get Date From Time
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC +0"));
Date date = new Date();
date.setTime(millisSinceMidnight);
cal.setTime(date);
return cal.getTime();