Java Utililty Methods String to Date

List of utility methods to do String to Date

Description

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

Method

StringaddTimeToDate(String date, int value, String unit, String sFormat)
This method adds time to a given date.
String sRealFormat = sFormat;
if ((sRealFormat == null) || sRealFormat.equals("")) {
    sRealFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
SimpleDateFormat UTCFormat = new SimpleDateFormat(sRealFormat);
Date dDate = new Date(); 
if ((date != null) && (date.length() != 0)) {
    try {
...
DategetStringToDate(String date, String format)
get String To Date
SimpleDateFormat simple = new SimpleDateFormat(format);
try {
    return simple.parse(date);
} catch (ParseException e) {
    return null;
DategetStringToDate(String date, String inputDateFormat)
get String To Date
return new SimpleDateFormat(inputDateFormat).parse(date);
DategetStringToDate(String pValue, String pDateFormat)
get String To Date
try {
    SimpleDateFormat formatter = new SimpleDateFormat(pDateFormat);
    formatter.setLenient(false);
    return formatter.parse(pValue);
} catch (Exception e) {
    return null;
DategetStringToDate(String str)
get String To Date
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date parse = null;
str = str.replace("T", " ");
try {
    parse = date.parse(str);
} catch (ParseException e) {
    e.printStackTrace();
return parse;
DategetStringToDateFull(String da)
get String To Date Full
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
    date = sdf.parse(da);
} catch (ParseException e) {
    try {
        sdf = new SimpleDateFormat("yyyy-MM-dd");
        date = sdf.parse(da);
...
DategetStringToDateTime(String dateStr, String formatStr)
get String To Date Time
SimpleDateFormat format = new SimpleDateFormat(formatStr);
Date date = null;
date = format.parse(dateStr);
return date;
StringgetTodateString()
get Todate String
String str = yyyyMMddHH_NOT_.format(new Date());
return str;
DatehumanDateToDate(String date)
human Date To Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(CURRENT_TIME_ZONE);
return sdf.parse(date);
StringLongToDateString(long l)
Long To Date String
DateFormat mediumDateFormat;
Date sDate;
try {
    mediumDateFormat = DateFormat.getDateTimeInstance();
    String date = String.valueOf(l);
    sDate = new Date(Long.parseLong(date));
} catch (Exception ex) {
    ex.printStackTrace();
...