Java Utililty Methods Time Parse

List of utility methods to do Time Parse

Description

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

Method

StringgetTimeFileName(String suffix)
get Time File Name
return formatDate(new Date(), "yyyyMMddHHmmssSSS") + suffix;
DategetTimeFromGermanLocale(String timeString)
Creates a date time value from a string.
try {
    return germanTime.parse(timeString);
} catch (Exception e) {
return null;
DategetTimeFromJsToJava(String date)
get Time From Js To Java
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.CHINA);
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = null;
try {
    d = utcFormat.parse(date);
} catch (Exception e) {
    e.printStackTrace();
return d;
longgetTimeFromString(String time)
get Time From String
SimpleDateFormat format = new SimpleDateFormat(dateFormatString);
try {
    Date date = format.parse(time);
    return date.getTime();
} catch (Exception e) {
    throw new RuntimeException(e);
ListgetTimeList(String start, String end, int pitch)
get Time List
List<String> result = new ArrayList<String>();
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
try {
    Date startDate = formatter.parse(start);
    Date endDate = formatter.parse(end);
    Calendar startCalendar = Calendar.getInstance();
    Calendar endCalendar = Calendar.getInstance();
    startCalendar.setTime(startDate);
...
StringgetTimeStr(String date1, String date2)
get Time Str
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
    long time = format.parse(date1).getTime() - format.parse(date2).getTime();
    long time1 = format.parse("1970-01-01 00:00:00").getTime() + time;
    return formatDate(new Date(time1), "HH:mm:ss");
} catch (ParseException e) {
    e.printStackTrace();
return "";
longgetTimeWithStr(String source, String pattern)
get Time With Str
return new SimpleDateFormat(pattern).parse(source).getTime();
longgetTimeX(String dateStr)
get Time X
long time = 0;
time = getDate(dateStr).getTime() / 1000;
return time;
booleanisDateTime(String dateTime)
is Date Time
int first = dateTime.indexOf(":");
int last = dateTime.lastIndexOf(":");
if (first == -1) {
    return false;
SimpleDateFormat df = null;
if (first == last) {
    df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
...
booleanisDateTime(String dateTime, String pattern)
is Date Time
DateFormat df = new SimpleDateFormat(pattern);
ParsePosition pos = new ParsePosition(0);
Date dt = df.parse(dateTime, pos);
return !(dt == null);