List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
private static Date getDistanceDate(Date date, int day) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from ww w .ja va2s . co m*/ cal.add(Calendar.DATE, day); return cal.getTime(); }
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 www. j a v a 2 s .c o m return dateParse(timeStampInMilliSeconds); }
From source file:Main.java
public static int getDaylightSavingsTimeOffset(long timeMs) { int dstOffset = 5; // default not daylight savings time Calendar c = Calendar.getInstance(); c.setTimeInMillis(timeMs);// w w w . java 2s.com int day = c.get(Calendar.DATE); int month = c.get(Calendar.MONTH); if ((month > DST_START_MONTH && month < DST_END_MONTH) || (month == DST_START_MONTH && day >= DST_START_DAY) || (month == DST_END_MONTH && day <= DST_END_DAY)) { dstOffset = 4; } return dstOffset; }
From source file:Main.java
/** * Returns two days old date from the current date. This is used with forusquare web service to get the data * according to date./* w ww .jav a 2 s . c o m*/ * * @return date in string. */ public static String getTwoDaysOldDate() { int yyyy = Calendar.getInstance().get(Calendar.YEAR); int MM = Calendar.getInstance().get(Calendar.MONTH) + 1; int dd = Calendar.getInstance().get(Calendar.DATE) - 2; Calendar cal = Calendar.getInstance(); if (dd < 1) { MM = MM - 1; if (MM < 0) { MM = 0; } } if (MM < 0) { yyyy = yyyy - 1; } cal.set(yyyy, MM, 1); dd = cal.getActualMaximum(Calendar.DATE) - dd; String oldDate = String.format("%04d%02d%02d", yyyy, MM, dd); return oldDate; }
From source file:Main.java
public static List<String> getWeekDate() { List<String> list = new ArrayList<String>(); Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); list.add(calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE)); for (int i = 0; i < 6; i++) { calendar.add(Calendar.DATE, 1); String str = calendar.get(Calendar.MONTH) + 1 + "." + calendar.get(Calendar.DATE); list.add(str);/*from w ww. java 2 s. c om*/ } return list; }
From source file:Main.java
public static Calendar getDateAwareCalendar() { Calendar calendar = new GregorianCalendar(); // Check if the 1st of September is in two weeks. If so we need to download full timetable // for two weeks beginning from the 1st of September in advance. if (calendar.get(Calendar.MONTH) == Calendar.AUGUST && calendar.get(Calendar.DATE) >= 18) { calendar.set(Calendar.MONTH, Calendar.SEPTEMBER); calendar.set(Calendar.DATE, 1); }/*www . java 2 s . c o m*/ prepareCalendarNoSunday(calendar); return calendar; }
From source file:Main.java
public static Calendar getFinishDate(String startDate, String duration) { try {//from w ww . j a v a2s . com SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); Calendar calendarFinish = Calendar.getInstance(); calendarFinish.setTime(sdf.parse(startDate)); calendarFinish.add(Calendar.DATE, Integer.parseInt(duration)); return calendarFinish; } catch (ParseException e) { Log.e("PARSE_FAIL", Log.getStackTraceString(e)); } return null; }
From source file:Main.java
public static long ArrivalMilliseconds(String arrivalTime) { Calendar calendarToday = Calendar.getInstance(); Calendar calendarTrainArrival = Calendar.getInstance(); long millisecondsTrainArrival; int nowYear = calendarToday.get(Calendar.YEAR); int nowMonth = calendarToday.get(Calendar.MONTH); int nowDay = calendarToday.get(Calendar.DATE); int evalhr = 0; int evalmin = 0; int evalsec = 0; String delims = "[:]"; String[] timesplit = arrivalTime.split(delims); evalhr = Integer.parseInt(timesplit[0]); //HR evalmin = Integer.parseInt(timesplit[1]); //MIN evalsec = Integer.parseInt(timesplit[2]); //SEC - VRE does not provide a schedule down to seconds, so ignore. calendarTrainArrival.set(nowYear, nowMonth, nowDay, evalhr, evalmin); millisecondsTrainArrival = calendarTrainArrival.getTimeInMillis(); return millisecondsTrainArrival; }
From source file:Main.java
public static String getSpecifiedDayAfter(String specifiedDay) { Calendar c = Calendar.getInstance(); Date date = null;/*from w ww. jav a 2 s . com*/ try { date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay); } catch (ParseException e) { e.printStackTrace(); } c.setTime(date); int day = c.get(Calendar.DATE); c.set(Calendar.DATE, day + 1); String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); return dayAfter; }
From source file:Main.java
public static int[] getSchoolCalDate(int year, int month, int day, int week, int dayOfWeek) { Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, day);//from w ww . j av a 2 s .co m Log.d(TAG, "Date: " + cal.toString()); Log.d(TAG, "year: " + year); Log.d(TAG, "month: " + month); Log.d(TAG, "day: " + day); cal.add(Calendar.DATE, -offset(cal.get(Calendar.DAY_OF_WEEK))); int count = (week - 1) * 7 + dayOfWeek - 1; Log.d(TAG, "count: " + count); cal.add(Calendar.DATE, count); int result[] = { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH) }; return result; }