List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:Main.java
/** * get a "clean" calendar as 1900-01-01 00:00:00 * * @return a "clean" calendar/*w w w .ja va 2 s . c o m*/ */ public static Calendar getCleanCalendar() { long time = convertDateStr2Millis("1900-01-01"); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar; }
From source file:Main.java
public static int[] getTimeFields(long time) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); int[] timeFields = new int[6]; timeFields[0] = calendar.get(Calendar.YEAR); timeFields[1] = calendar.get(Calendar.MONTH); timeFields[2] = calendar.get(Calendar.DAY_OF_MONTH); timeFields[3] = calendar.get(Calendar.HOUR_OF_DAY); timeFields[4] = calendar.get(Calendar.MINUTE); timeFields[5] = calendar.get(Calendar.SECOND); return timeFields; }
From source file:Main.java
/** * Add date time with almost one month./*ww w .ja v a2s . c o m*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithAlmostOneMonth(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.DAY_OF_MONTH, isPast ? -30 : 30); listing.add(calendar.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()); }//ww w. ja v a 2s . com return dateParse(timeStampInMilliSeconds); }
From source file:Main.java
/** * Add date time with ten days./* w ww . j a v a 2 s .co m*/ * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithTenDays(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.DAY_OF_MONTH, isPast ? -10 : 10); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with almost one year.//from ww w . java2s .c o m * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithAlmostOneYear(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.MONTH, isPast ? -12 : 12); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with one day.//from w ww .j a va2 s . com * * @param listing the listing * @param currentTime the current time * @param isPast true/false if past time */ private static void addDateTimeWithOneDay(final List<Long> listing, final long currentTime, final boolean isPast) { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); calendar.add(Calendar.DAY_OF_MONTH, isPast ? -1 : 1); listing.add(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Add date time with almost two years.//from w ww. j av a 2s . 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 w w w . j a va2 s . com*/ * * @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
public static int StampToDateInt(long stamp) { int date = 0; Date datetime = null;/*from www .ja v a 2 s. com*/ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(stamp); datetime = calendar.getTime(); String format = STAMP_TO_DATE_INT; SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_PRC)); try { date = Integer.parseInt(sdf.format(datetime)); } catch (Exception e) { e.printStackTrace(); } //Log.i("StampHelper", "date_int:"+date); return date; }