List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static void setTimerReceiver(Context context, int repeat_time, Class<?> class_name) { AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intentReceiver = new Intent(context, class_name); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intentReceiver, PendingIntent.FLAG_CANCEL_CURRENT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, repeat_time / 1000); // InexactRepeating allows Android to optimize the energy consumption alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeat_time, pendingIntent); }
From source file:Main.java
public static long getTimesMonthMorning() { 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.getActualMinimum(Calendar.DAY_OF_MONTH)); return cal.getTimeInMillis(); }
From source file:Main.java
public static long getStartOfTheDay(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date);/*from ww w. jav a 2 s.c o m*/ c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }
From source file:Main.java
public static long firstOfTheMonth9am() { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.HOUR_OF_DAY, 9); c.set(Calendar.MINUTE, 0);// w w w .j a v a 2s .c o m c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }
From source file:Main.java
public static long formatTimeString(String timeString) { long time = 0; if (timeString == null || timeString.length() < 1) { return time; }//w w w. j av a 2 s .com try { String[] array = timeString.split(DASH); int year = Integer.valueOf(array[0]); int month = Integer.valueOf(array[1]); int day = Integer.valueOf(array[2]); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); time = calendar.getTimeInMillis(); } catch (Exception e) { e.printStackTrace(); } return time; }
From source file:Main.java
public static Intent newCalendarIntent(Context context, Date startDate, String title, String location, String note) {//from www. j a v a2 s.co m Calendar cal = Calendar.getInstance(); cal.setTime(startDate); Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", cal.getTimeInMillis()); intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000); intent.putExtra("allDay", true); //intent.putExtra("rrule", "FREQ=WEEKLY;COUNT="+numWeeks); //intent.putExtra("rrule", "FREQ=YEARLY"); intent.putExtra("title", title); intent.putExtra("eventLocation", location); intent.putExtra("description", note); //intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); //intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); return intent; }
From source file:Main.java
/** * Add date time with almost two years.//from w w w .j av a2s . co m * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithAlmostTwoYears(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MONTH, isPast ? -10 : 10); calendar.add(Calendar.YEAR, isPast ? -1 : 1); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with five years.//from ww w. j ava 2s .c o m * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithFiveYears(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MONTH, isPast ? -10 : 10); calendar.add(Calendar.YEAR, isPast ? -5 : 5); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
private static long getTimeInMillis() { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, 21); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static String getFormatedDate(String rawDate, Boolean flag) { Calendar currenttime = Calendar.getInstance(); Calendar commentTime = Calendar.getInstance(); long nextDateInMillis = currenttime.getTimeInMillis(); long commentTimeInMillis = Long.parseLong(rawDate) * 1000; commentTime.setTimeInMillis(commentTimeInMillis); long timeDifferenceMilliseconds = nextDateInMillis - commentTimeInMillis; long diffSeconds = timeDifferenceMilliseconds / 1000; long diffMinutes = timeDifferenceMilliseconds / (60 * 1000); long diffHours = timeDifferenceMilliseconds / (60 * 60 * 1000); long diffDays = timeDifferenceMilliseconds / (60 * 60 * 1000 * 24); // long diffWeeks = timeDifferenceMilliseconds / (60 * 60 * 1000 * 24 * // 7);//from www . ja va2 s.c om // long diffMonths = (long) (timeDifferenceMilliseconds / (60 * 60 * // 1000 * 24 * 30.41666666)); // long diffYears = (long) (timeDifferenceMilliseconds / (60 * 60 * 1000 // * 24 * 365)); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd"); if (flag) { if (diffSeconds < 1) { return "less than a second"; } else if (diffMinutes < 1) { return diffSeconds + "s"; } else if (diffHours < 1) { return diffMinutes + "m"; } else if (diffDays < 1) { return diffHours + "h"; } else if (diffDays < 7) { return diffDays + "d"; } else { return sdf.format(commentTime.getTime()); } } else { if (diffSeconds < 1) { return "Posted Just Now"; } else if (diffMinutes < 1) { if (diffSeconds == 1) return diffSeconds + " second ago"; else return diffSeconds + " seconds ago"; } else if (diffHours < 1) { if (diffMinutes == 1) return diffMinutes + " minute ago"; else return diffMinutes + " minutes ago"; } else if (diffDays < 1) { if (diffHours == 1) return diffHours + " hour ago"; else return diffHours + " hours ago"; } else if (diffDays < 7) { if (diffDays == 1) return diffDays + " day ago"; else return diffDays + " days ago"; } else { return sdf.format(commentTime.getTime()); } } }