List of utility methods to do Date Parse
Date | dateParser(String param) date Parser Date date = null; try { date = dateFormatter.parse(param); } catch (ParseException ex) { return date; |
String | dateParseShortString(Date date) date Parse Short String java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); return df.format(date); |
Date | dateStringToDate(String dateString, String DateStringType) date String To Date SimpleDateFormat formatter = new SimpleDateFormat(DateStringType); Date t = null; try { return formatter.parse(dateString); } catch (Exception e) { return t; |
Date | dateStringToDateObject(String dateString, String dateFormat) Converts a given dateString to a date object using the given dateFormat Date date; SimpleDateFormat format = new SimpleDateFormat(dateFormat); date = format.parse(dateString); return date; |
Date | datetime(String s) datetime return parsedate(s, FMT_DATETIME);
|
Date | dateTime(String s) date Time List<DateFormat> formats = asList(dateTimeFormat("kk:mm dd/MM/yyyy", UTC), dateTimeFormat("kk:mm:ss dd/MM/yyyy", UTC), dateTimeFormat("kk:mm:ss.SSS dd/MM/yyyy", UTC), dateTimeFormat("E MMM dd kk:mm:ss Z yyyy", UTC)); for (DateFormat format : formats) { try { return format.parse(s); } catch (ParseException ignored) { throw new RuntimeException("Failed to parse string as dateTime: " + s); |
Date | datetimeParse(String datetime) datetime Parse SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date2 = null; try { date2 = sdf.parse(datetime); } catch (ParseException e) { e.printStackTrace(); return date2; ... |
String | DateTimeParse(String DateTimeString, String LMS) Date Time Parse String parsedDate = ""; Date dte = null; DateFormat formatter = null; try { if (LMS.equals("WebCT")) { formatter = new SimpleDateFormat("MMM ddd,yyyy hh:mm a"); dte = (Date) formatter.parse(DateTimeString); } else if (LMS.equals("Moodle")) { ... |
Date | getDateFromCurrentAnd24HRTime(Date current, String hr24Time) get Date From Current And HR Time Calendar calendar = Calendar.getInstance(); calendar.setTime(current); int day = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); Calendar newCalendar = Calendar.getInstance(); newCalendar.set(Calendar.DAY_OF_MONTH, day); newCalendar.set(Calendar.MONTH, month); ... |
Date | getDateFromDateAge(Date currentDate, String age) Retrieves the original date by current date and an age. Calendar cal = Calendar.getInstance(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String nowString = sdf.format(currentDate); cal.setTime(sdf.parse(nowString)); } catch (ParseException e) { cal.setTime(currentDate); if (age.contains("m") || age.contains("M")) { age = age.replace("m", ""); age = age.replace("M", ""); int months = Integer.parseInt(age) * -1; cal.add(Calendar.MONTH, months); } else { double years = Double.parseDouble(age) * -1; cal.add(Calendar.YEAR, (int) years); return cal.getTime(); |