List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static long getEndOfCurrentYear() { Calendar calendar = getCurrentCalendar(); calendar.set(Calendar.MONTH, 11); return calendar.getTimeInMillis(); }
From source file:Main.java
public static long getUTCTime() { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("gmt")); return cal.getTimeInMillis(); }
From source file:Main.java
public static int getTimestamp(String targetTime, long currentTime) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(targetTime));//from w w w . ja v a 2 s.c o m long time1 = cal.getTimeInMillis(); long between_days = (time1 - currentTime) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(between_days)); }
From source file:Main.java
public static Boolean isToday(long millis) { Calendar today = Calendar.getInstance(); today = clearTimes(today);//from w w w . j a v a 2 s . c o m if (millis > today.getTimeInMillis()) return true; return false; }
From source file:Main.java
static public int getTimestamp() { Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT")); long millis = calendar.getTimeInMillis(); long stamp = millis - mCalendarGenMs; stamp = (stamp + 500) / 1000;// ww w. j ava2 s .c om return (int) stamp; }
From source file:org.jfree.chart.demo.WindChartDemo1.java
private static long millisForDate(int i, int j, int k) { Calendar calendar = Calendar.getInstance(); calendar.set(k, j - 1, i, 12, 0);//from w w w . ja va 2 s. co m return calendar.getTimeInMillis(); }
From source file:Main.java
public static int compareDate(Calendar time1, Calendar time2) { int result = -1; if (time1.getTimeInMillis() == time2.getTimeInMillis()) { result = 0;/* w w w . ja va2 s .c om*/ } else if (time1.get(Calendar.YEAR) == time2.get(Calendar.YEAR)) { result = 6; if (time1.get(Calendar.MONTH) == time2.get(Calendar.MONDAY)) { result = 5; if (time1.get(Calendar.DAY_OF_MONTH) == time2.get(Calendar.DAY_OF_MONTH)) { result = 4; if (time1.get(Calendar.HOUR_OF_DAY) == time2.get(Calendar.HOUR_OF_DAY)) { result = 3; if (time1.get(Calendar.MINUTE) == time2.get(Calendar.MINUTE)) { result = 2; if (time1.get(Calendar.SECOND) == time2.get(Calendar.SECOND)) { result = 1; } } } } } } else if (time1.get(Calendar.YEAR) / 100 == time2.get(Calendar.YEAR) / 100) { result = 7; } return result; }
From source file:Main.java
public static long getStartOfCurrentMonth() { Calendar calendar = getCurrentCalendar(); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTimeInMillis(); }
From source file:Main.java
/** * Return the difference between 2 dates (dayTwo - dayOne) in days * @param dayTwo The first day to compare against * @param dayOne The second day to compare against * @return an int of the difference between the 2 days */// w ww .j a va 2s.c om public static int diffDays(Date dayTwo, Date dayOne) { Calendar calOne = Calendar.getInstance(); calOne.setTime(dayOne); long msOne = calOne.getTimeInMillis(); Calendar calTwo = Calendar.getInstance(); calTwo.setTime(dayTwo); long msTwo = calTwo.getTimeInMillis(); return (int) ((msTwo - msOne) / (1000L * 60L * 60L * 24L)); }
From source file:Main.java
public static long getDate(int year, int monthOfYear, int dayOfMonth) { Calendar c = Calendar.getInstance(); c.set(year, monthOfYear, dayOfMonth); return c.getTimeInMillis(); }