Android Utililty Methods Date String Parse

List of utility methods to do Date String Parse

Description

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

Method

DateString2Date(String dateStr)
String Date
Date date = null;
try {
    date = dateFormate.parse(dateStr);
} catch (java.text.ParseException e) {
    e.printStackTrace();
return date;
StringchangeDateWithSplit(String argDate, String split)
change Date With Split
if (argDate == null || argDate.trim().equals("")) {
    return "";
if (split == null || split.trim().equals("")) {
    split = "-";
String result = "";
if (argDate.length() == 10 && argDate.indexOf("/") > 0) {
...
booleanisValidDate(String sDate)
is Valid Date
String datePattern1 = "\\d{4}-\\d{2}-\\d{2}";
String datePattern2 = "^((\\d{2}(([02468][048])|([13579][26]))"
        + "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|"
        + "(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"
        + "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?("
        + "(((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?"
        + "((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
if ((sDate != null)) {
...
DategetDateTimeFromString(String dateTimeString, String format)
get Date Time From String
SimpleDateFormat dateFormat = new SimpleDateFormat(format,
        Locale.getDefault());
try {
    return dateFormat.parse(dateTimeString);
} catch (ParseException e) {
    Log.e(TAG, "Converting datetime from string error");
    e.printStackTrace();
    return null;
...
DateconvertStringToDate(String date, String time)
convert String To Date
SimpleDateFormat formatter = new SimpleDateFormat(
        "dd-MM-yyyy hh:mm a");
String dateString = date + " " + time;
Date newDate = null;
try {
    newDate = (Date) formatter.parse(dateString);
} catch (java.text.ParseException e) {
    Log.w(TAG, invalidDateFormat);
...
DateGetDate(String time)
Get Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
    return sdf.parse(time);
} catch (ParseException e) {
    return new Date();
DatedateTimeToDateObj(String date, String time)
date Time To Date Obj
java.util.Calendar cal = java.util.Calendar.getInstance();
int[] dateTokens;
dateTokens = tokenizeDate(date);
cal.set(java.util.Calendar.YEAR, dateTokens[2]);
cal.set(java.util.Calendar.MONTH, dateTokens[0] - 1);
cal.set(java.util.Calendar.DATE, dateTokens[1]);
int[] timeTokens;
timeTokens = tokenizeTime(time);
...
DatefromSlDateTime(final String dateString, final String timeString)
Constructs a Date from the provided date and time.
String dateTime = String.format("%s %s", dateString, timeString);
Date date = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
        "dd.MM.yy HH:mm");
try {
    date = simpleDateFormat.parse(dateTime);
} catch (ParseException e) {
    e.printStackTrace();
...
StringconvertTimeStumpToDate(String time)
convert Time Stump To Date
try {
    return dateFormater.format(new Date(toLong(time) * 1000L));
} catch (Exception e) {
    return null;
StringconvertimeStumpToDate2(String time)
convertime Stump To Date
try {
    return dateFormater2.format(new Date(toLong(time) * 1000L));
} catch (Exception e) {
    return null;