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

DatestrToDate(String time, String format)
Convert String of day to Date type
DateFormat formater = new SimpleDateFormat(format);
return formater.parse(time);
StringstrToDate3(String i_StrDate)
str To Date
try {
    if (i_StrDate == null || "".equals(i_StrDate.trim())) {
        return "";
    java.util.Date d = SDF_FULL.parse(i_StrDate);
    return SDF_FULL.format(d);
} catch (Exception e) {
    e.printStackTrace();
...
DatestrToDateM6(String StrToDate)
StrToDate 'yyyy-MM-dd HH:mm:ss'
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
try {
    return simpleDateFormat.parse(StrToDate);
} catch (ParseException e) {
return null;
DateStrToDateSeco(String str)
Str To Date Seco
Date parse = null;
try {
    parse = seconParse.parse(str);
} catch (ParseException e) {
    e.printStackTrace();
return parse;
DatestrToDatetime(String sStr)
str To Datetime
if (sStr == null) {
    return null;
SimpleDateFormat formatter;
if (sStr.length() == 19) {
    formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else if (sStr.length() == 10) {
    formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
...
DatestrToDateWithFormat(String strDate, Format format)
str To Date With Format
SimpleDateFormat localFormat = (SimpleDateFormat) format;
ParsePosition pos = new ParsePosition(0);
Date strtodate = localFormat.parse(strDate, pos);
return strtodate;
DateTimeStringToDate(String s)
Time String To Date
Date date = new Date();
try {
    SimpleDateFormat simpledateformat = new SimpleDateFormat("HH:mm:ss");
    ParsePosition parseposition = new ParsePosition(0);
    date = simpledateformat.parse(s, parseposition);
} catch (Exception ex) {
return date;
...
DatetimeToDate(String time)
time To Date
Date fecha = null;
try {
    SimpleDateFormat sdf;
    if (time.length() == 5) {
        sdf = new SimpleDateFormat("HH:mm");
    } else if (time.length() == 8) {
        sdf = new SimpleDateFormat("HH:mm:ss");
    } else {
...
DatetoDate(DateFormat format, String value)
to Date
return toDate(format, value, null);
StringtoDate(final Long date, final String pattern)
to Date
final long millis = Long.valueOf(date).longValue() * 1000;
final Date d = new Date(millis);
final SimpleDateFormat sdf = new SimpleDateFormat(pattern); 
return sdf.format(d);