List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static String timeToDeparture(String startTime) { int diffMinutes = -1; Calendar now = Calendar.getInstance(); now.setTime(new Date()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date = null;// w ww . ja v a 2 s.c om try { date = dateFormat.parse(startTime); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(date); long millisDiff = cal.getTimeInMillis() - now.getTimeInMillis(); if (millisDiff > 0) { diffMinutes = ((int) millisDiff / (60 * 1000)); } return String.valueOf(diffMinutes); }
From source file:Main.java
public static long getTime(int year, int month, int day, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, day, hourOfDay, minute); return calendar.getTimeInMillis(); }
From source file:Main.java
public static void d(String tag, String message, boolean printTime) { Calendar current = Calendar.getInstance(); long endLogTimeInMillis = current.getTimeInMillis(); Log.d(tag, message + ":" + (endLogTimeInMillis - startLogTimeInMillis) + "ms"); }
From source file:Main.java
/** * Get passed time from given date/*from w w w. j ava2 s. com*/ * * @param date * @return */ public static String getTimeString(Date date) { String strTime = ""; Calendar thatDay = Calendar.getInstance(); thatDay.setTime(date); Calendar today = Calendar.getInstance(); long diff = today.getTimeInMillis() - thatDay.getTimeInMillis(); //result in millis long second = diff / 1000; int min = (int) second / 60; int hour = min / 60; int day = hour / 24; int month = day / 30; int year = month / 12; if (min < 60) { strTime = String.format("%d min", min); } else if (min >= 60 && min < 60 * 24) { if (hour < 24) { strTime = String.format("%d hour", hour); } } else if (day < 31) { strTime = String.format("%d day", day); } else if (month < 12) { strTime = String.format("%d month", month); } else { strTime = String.format("%d year", year); } return strTime; }
From source file:Main.java
public static int intervalDayBetweenDate(Calendar cl1, Calendar cl2) { long interval = 0; if (cl1.after(cl2)) { interval = cl1.getTimeInMillis() - cl2.getTimeInMillis(); } else {//from www . ja v a 2s .co m interval = cl2.getTimeInMillis() - cl1.getTimeInMillis(); } return (int) (interval / MS_OF_ONE_DAY); }
From source file:Main.java
public static Long getIncTimeInMillis(Date originDate, int increment) { if (null == originDate) return null; Calendar c = Calendar.getInstance(); c.setTime(originDate);/* w w w . ja va2s . c o m*/ c.add(Calendar.MINUTE, increment); return c.getTimeInMillis(); }
From source file:Main.java
/** * Convert date into milliseconds.//w w w .j a va 2 s . com * * @param crisisDate * @return */ public static long getMiliseconds(String crisisDate) { try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); Date date = (Date) formatter.parse(crisisDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.getTimeInMillis(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
From source file:Main.java
public static long getLocalToUtcDelta() { Calendar local = Calendar.getInstance(); local.clear();/* w w w . j a v a2s. co m*/ local.set(1970, Calendar.JANUARY, 1, 0, 0, 0); return local.getTimeInMillis(); }
From source file:Main.java
/** * Gets the minutes between two Calendars * @param startTime The start time//w ww. j a v a2s .co m * @param endTime The end time * @return The number of minutes between the two Calendars */ public static double getMinutes(Calendar startTime, Calendar endTime) { if (startTime == null || endTime == null) { return 0; } return ((double) (endTime.getTimeInMillis() - startTime.getTimeInMillis())) / 60000; }
From source file:Main.java
public static java.util.Date toDate(Calendar c) { if (c == null) return null; java.util.Date date = new java.util.Date(); date.setTime(c.getTimeInMillis()); return date;//from ww w.jav a2s .c o m }