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

StringgetTime(String pattern)
get Time
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(now);
longgetTime(String s)
get Time
return parseMysql(s).getTime();
intgetTime(String sDateTime, String eDateTime)
get Time
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date ssDateTime = myFormatter.parse(sDateTime);
java.util.Date eeDateTime = myFormatter.parse(eDateTime);
long l = (eeDateTime.getTime() - ssDateTime.getTime());
long day = l / (24 * 60 * 60 * 1000);
return (int) day;
longgetTime(String time)
get Time
SimpleDateFormat shijian = new SimpleDateFormat("yyyy-MM-dd");
long longtime = 0;
try {
    longtime = shijian.parse(time).getTime();
} catch (Exception e) {
return longtime;
DategetTime(String time)
get Time
return getDateTime(time, DEFAULT_FORMAT_TIME);
DategetTimeDate(String time)
get Time Date
String string = sdf.format(getCurrentDateTime());
string += " " + time;
Date date = null;
try {
    date = sdf2.parse(string);
} catch (ParseException e) {
    e.printStackTrace();
return date;
ListgetTimes(String startTime, String endTime)
get Times
List<String> dayList = new ArrayList<String>();
try {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date startDate = df.parse(startTime);
    Date endDate = df.parse(endTime);
    String now = "";
    for (long i = startDate.getTime(); i <= endDate.getTime(); i += (long) 24 * (long) 3600 * (long) 1000) {
        Date date = new Date(i);
...
StringreplaceDateTime(String input)
* If the input String contains the sequence {date}pattern{date}, replaces the first occurrence of this sequence with a UTC date/time string formatted according to pattern.
String output = input;
try {
    String token = "{date}";
    if (isNonEmptyString(output) && output.contains(token)) {
        int tlen = token.length();
        StringBuilder sb = new StringBuilder(output);
        int p1f = sb.indexOf(token);
        while (p1f > -1) {
...
Datestr2DateTime(String strDate)
yyyy-MM-dd HH:mm:ss
DateFormat df = DateFormat.getDateTimeInstance();
Date date = null;
try {
    date = df.parse(strDate);
} catch (ParseException e) {
    e.printStackTrace();
return date;
...
Datestring2Date(String time)
string Date
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhssmm");
Date date = new Date();
try {
    date = dateFormat.parse(time);
} catch (ParseException e) {
    e.printStackTrace();
return date;
...