List of usage examples for java.util Calendar set
public final void set(int year, int month, int date)
YEAR
, MONTH
, and DAY_OF_MONTH
. 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); 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; }
From source file:Main.java
public static Calendar createNewCalendar(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.clear();/*from w ww . j a v a 2 s .c om*/ calendar.set(year, month - 1, day); return calendar; }
From source file:Main.java
public static Calendar str2calendar(String str) { if (TextUtils.isEmpty(str)) return null; String[] strList = str.split("-"); if (strList.length != 3 || !isNumber(strList[0]) || !isNumber(strList[1]) || !isNumber(strList[2])) return null; int year = Integer.parseInt(strList[0]); int month = Integer.parseInt(strList[1]); int day = Integer.parseInt(strList[2]); Calendar result = Calendar.getInstance(); result.set(year, month - 1, day); return result; }
From source file:Main.java
public static Date getDateObj(int year, int month, int day) { Calendar c = new GregorianCalendar(); c.set(year, month - 1, day); return c.getTime(); }
From source file:Main.java
public static long getDateMills(int year, int month, int day) { //Date d = new Date(year, month, day); // 1960 4 22//from ww w. j a v a 2s .c o m Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.set(year, month, day); TimeZone tz = TimeZone.getDefault(); calendar.setTimeZone(tz); return calendar.getTimeInMillis(); }
From source file:org.jfree.chart.demo.YIntervalChartDemo2.java
private static void add(YIntervalSeries yintervalseries, int i, int j, int k, double d, double d1) { Calendar calendar = Calendar.getInstance(); calendar.set(i, j, k); yintervalseries.add(calendar.getTime().getTime(), d, d - d1, d + d1); }
From source file:Main.java
private static int getWeekViewStartDiff(int year, int month, int day, int weekStart) { java.util.Calendar date = java.util.Calendar.getInstance(); date.set(year, month - 1, day);// int week = date.get(java.util.Calendar.DAY_OF_WEEK); if (weekStart == 1) { return week - 1; }//from w w w. ja v a2 s. c o m if (weekStart == 2) { return week == 1 ? 6 : week - weekStart; } return week == 7 ? 0 : week; }
From source file:Main.java
private static int getWeekViewEndDiff(int year, int month, int day, int weekStart) { java.util.Calendar date = java.util.Calendar.getInstance(); date.set(year, month - 1, day); int week = date.get(java.util.Calendar.DAY_OF_WEEK); if (weekStart == 1) { return 7 - week; }/*from ww w .j av a 2s . c o m*/ if (weekStart == 2) { return week == 1 ? 0 : 7 - week + 1; } return week == 7 ? 6 : 7 - week - 1; }
From source file:Main.java
/** * Returns Epoch date, ie. 01/01/1970.//from ww w .j a va 2 s . c om * * @return Epoch date, ie. 01/01/1970. */ public static Date getEpoch() { final Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(1970, 0, 1); return calendar.getTime(); }
From source file:IntDate.java
public static Date getDate(String year, String month, String day) { // Date(int, int, int) has been deprecated, so use Calendar to // set the year, month, and day. Calendar c = Calendar.getInstance(); // Convert each argument to int. c.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); return c.getTime(); }