List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static long getTimeStampStartOfDay(long time) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTime(new Date(time)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//from w w w .j a v a 2 s . co m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:Main.java
public static long getYearMonthDay(long date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date);//from www . jav a2 s. c om calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Long GetUTCTime() { Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); int zoneOffset = cal.get(Calendar.ZONE_OFFSET); int dstOffset = cal.get(Calendar.DST_OFFSET); cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset)); return cal.getTimeInMillis(); }
From source file:Main.java
public static String getFormattedDate(long timeStampInMilliSeconds) { Calendar smsTime = Calendar.getInstance(); smsTime.setTimeInMillis(timeStampInMilliSeconds); Calendar now = Calendar.getInstance(); if (now.get(Calendar.DATE) == smsTime.get(Calendar.DATE)) { return "Today " + getTime(smsTime.getTimeInMillis()); } else if (now.get(Calendar.DATE) - smsTime.get(Calendar.DATE) == 1) { return "Yesterday " + getTime(smsTime.getTimeInMillis()); }//from w ww.j ava2 s. co m return dateParse(timeStampInMilliSeconds); }
From source file:Main.java
public static long getCountDownDays(int dayMonth, int month, int year) { Calendar thatDay = Calendar.getInstance(); thatDay.set(Calendar.DAY_OF_MONTH, dayMonth); thatDay.set(Calendar.MONTH, month - 1); // 0-11 so 1 less thatDay.set(Calendar.YEAR, year); Calendar today = Calendar.getInstance(); long diff = thatDay.getTimeInMillis() - today.getTimeInMillis(); return diff / (24 * 60 * 60 * 1000); }
From source file:Main.java
public static long getTimesMonthNextStart() { Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, 24); return cal.getTimeInMillis(); }
From source file:Main.java
public static long getYearStart() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/* www . j av a 2s .com*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarAfter(Calendar date) { Calendar endDate = Calendar.getInstance(); endDate.setTimeInMillis(date.getTimeInMillis()); endDate.add(Calendar.DAY_OF_MONTH, 1 + random.nextInt(10)); return endDate; }
From source file:com.silverpeas.jcrutil.RandomGenerator.java
public static Calendar getCalendarBefore(Calendar date) { Calendar beforeDate = Calendar.getInstance(); beforeDate.setTimeInMillis(date.getTimeInMillis()); beforeDate.add(Calendar.DAY_OF_MONTH, -1 - random.nextInt(10)); return beforeDate; }
From source file:Main.java
@SuppressLint("NewApi") private static void setAlarm(Context context, Calendar calendar, PendingIntent pIntent) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent); } else {/*from w w w. ja v a 2 s. c o m*/ alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent); } }