@Test public void getLongFromDateTimeTest(){ String date="2020-03-12"; String dateformat="yyyy-MM-dd"; String time="15:15:15"; String timeformat="HH:mm:ss"; Calendar calendar=DateUtils.getLongFromDateTime(date,dateformat,time,timeformat); assertEquals(calendar.get(Calendar.YEAR),2020); assertEquals(calendar.get(Calendar.MONTH),2); assertEquals(calendar.get(Calendar.DATE),12); assertEquals(calendar.get(Calendar.HOUR_OF_DAY),15); assertEquals(calendar.get(Calendar.MINUTE),15); assertEquals(calendar.get(Calendar.SECOND),0); }
public static Calendar getLongFromDateTime (String date, String dateFormat, String time, String timeFormat) { Calendar cal = Calendar.getInstance(); Calendar cDate = Calendar.getInstance(); Calendar cTime = Calendar.getInstance(); SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat); SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat); try { cDate.setTime(sdfDate.parse(date)); cTime.setTime(sdfTime.parse(time)); } catch (ParseException e) { LogDelegate.e("Date or time parsing error: " + e.getMessage()); } cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, 0); return cal; }
DateUtils { public static Calendar getLongFromDateTime (String date, String dateFormat, String time, String timeFormat) { Calendar cal = Calendar.getInstance(); Calendar cDate = Calendar.getInstance(); Calendar cTime = Calendar.getInstance(); SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat); SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat); try { cDate.setTime(sdfDate.parse(date)); cTime.setTime(sdfTime.parse(time)); } catch (ParseException e) { LogDelegate.e("Date or time parsing error: " + e.getMessage()); } cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, 0); return cal; } }
DateUtils { public static Calendar getLongFromDateTime (String date, String dateFormat, String time, String timeFormat) { Calendar cal = Calendar.getInstance(); Calendar cDate = Calendar.getInstance(); Calendar cTime = Calendar.getInstance(); SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat); SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat); try { cDate.setTime(sdfDate.parse(date)); cTime.setTime(sdfTime.parse(time)); } catch (ParseException e) { LogDelegate.e("Date or time parsing error: " + e.getMessage()); } cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, 0); return cal; } private  DateUtils(); }
DateUtils { public static Calendar getLongFromDateTime (String date, String dateFormat, String time, String timeFormat) { Calendar cal = Calendar.getInstance(); Calendar cDate = Calendar.getInstance(); Calendar cTime = Calendar.getInstance(); SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat); SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat); try { cDate.setTime(sdfDate.parse(date)); cTime.setTime(sdfTime.parse(time)); } catch (ParseException e) { LogDelegate.e("Date or time parsing error: " + e.getMessage()); } cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, 0); return cal; } private  DateUtils(); static String getString(long date, String format); static String getString(Date d, String format); static Calendar getDateFromString(String str, String format); static Calendar getLongFromDateTime(String date, String dateFormat, String time, String timeFormat); static Calendar getCalendar(Long dateTime); static String getLocalizedDateTime(Context mContext,
      String dateString, String format); static boolean is24HourMode(Context mContext); static boolean isSameDay(long date1, long date2); static long getNextMinute(); static long getPresetReminder(Long currentReminder); static Long getPresetReminder(String alarm); static boolean isFuture(String timestamp); static boolean isFuture(Long timestamp); static String prettyTime(String timeInMillisec); static String prettyTime(Long timeInMillisec); }
DateUtils { public static Calendar getLongFromDateTime (String date, String dateFormat, String time, String timeFormat) { Calendar cal = Calendar.getInstance(); Calendar cDate = Calendar.getInstance(); Calendar cTime = Calendar.getInstance(); SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat); SimpleDateFormat sdfTime = new SimpleDateFormat(timeFormat); try { cDate.setTime(sdfDate.parse(date)); cTime.setTime(sdfTime.parse(time)); } catch (ParseException e) { LogDelegate.e("Date or time parsing error: " + e.getMessage()); } cal.set(Calendar.YEAR, cDate.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cDate.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cDate.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, 0); return cal; } private  DateUtils(); static String getString(long date, String format); static String getString(Date d, String format); static Calendar getDateFromString(String str, String format); static Calendar getLongFromDateTime(String date, String dateFormat, String time, String timeFormat); static Calendar getCalendar(Long dateTime); static String getLocalizedDateTime(Context mContext,
      String dateString, String format); static boolean is24HourMode(Context mContext); static boolean isSameDay(long date1, long date2); static long getNextMinute(); static long getPresetReminder(Long currentReminder); static Long getPresetReminder(String alarm); static boolean isFuture(String timestamp); static boolean isFuture(Long timestamp); static String prettyTime(String timeInMillisec); static String prettyTime(Long timeInMillisec);  }