List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:Main.java
private static Date getTomorrowMorning4am() { Calendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DATE, fONE_DAY); Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), fFOUR_AM, fZERO_MINUTES); return result.getTime(); }
From source file:Main.java
public static boolean isSameDay(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); }// www. j a v a2 s . c om return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)); }
From source file:Main.java
public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) { String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); File imageFile = new File(mPath); boolean create = imageFile.mkdirs(); boolean canWrite = imageFile.canWrite(); Calendar cal = Calendar.getInstance(); String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE); String filename = null;// ww w . j a va2s . co m int i = 0; while (imageFile.exists()) { i++; filename = date + "_mandelbrot" + i + ".png"; imageFile = new File(mPath, filename); boolean canWrite2 = imageFile.canWrite(); } try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos); byte[] bitmapdata = bos.toByteArray(); //write the bytes in file FileOutputStream fos = new FileOutputStream(imageFile); fos.write(bitmapdata); fos.flush(); fos.close(); Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(imageFile)); activity.sendBroadcast(intent); displaySuccesToast(activity); } catch (FileNotFoundException e) { displayFileError(activity); e.printStackTrace(); } catch (IOException e) { displayFileError(activity); e.printStackTrace(); } return bitmap; }
From source file:Main.java
/** * Adds to the given <code>JComponent</code> two date spinners * labeled "To" and "From". Used to specify a specific date range. The * default range is -10 years from today's date through today's date. * @param c - <code>JComponent</code> to add the date spinners to *///from w ww. ja v a 2s . co m public static void addDateRangePanel(JComponent c) { Calendar calendar = Calendar.getInstance(); JSpinner dateSpinner; //Set up dates Date initDate = calendar.getTime(); Date latestDate = calendar.getTime(); calendar.add(Calendar.YEAR, -10); Date earliestDate = calendar.getTime(); //Date Spinners SpinnerModel fromModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.DAY_OF_MONTH); dateSpinner = addLabeledSpinner(c, "From: ", fromModel, false); dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/dd/yyyy")); SpinnerModel toModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.DAY_OF_MONTH); dateSpinner = addLabeledSpinner(c, "To: ", toModel, true); dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/dd/yyyy")); }
From source file:Main.java
/** * Converts input time from Java to DOS format * @param time//from ww w. j a va 2 s . co m * @return time in DOS format */ public static long javaToDosTime(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); int year = cal.get(Calendar.YEAR); if (year < 1980) { return (1 << 21) | (1 << 16); } return (year - 1980) << 25 | (cal.get(Calendar.MONTH) + 1) << 21 | cal.get(Calendar.DATE) << 16 | cal.get(Calendar.HOUR_OF_DAY) << 11 | cal.get(Calendar.MINUTE) << 5 | cal.get(Calendar.SECOND) >> 1; }
From source file:Main.java
/** * Builds a simple hash for a day by concatenating year and day of year together. Note that two * {@link java.util.Calendar} inputs that fall on the same day will be hashed to the same * string.// w w w.ja v a 2 s. c om */ public static String getHashedDay(Calendar day) { return day.get(Calendar.YEAR) + "-" + day.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static boolean isYearSet(Calendar cal) { // use the Calendar.YEAR field to track whether or not the year is set instead of // Calendar.isSet() because doing Calendar.get() causes Calendar.isSet() to become // true irregardless of what the previous value was return cal.get(Calendar.YEAR) > 1; }
From source file:Main.java
/** * Check if given Calendar object represents a holiday. * * @param cal/*www . j a v a2s . c o m*/ * The Calendar to check. * @return true if holiday, false otherwise. */ private static boolean isHoliday(Calendar cal) { int year = cal.get(Calendar.YEAR); Set<?> yearSet = getHolidaySet(year); for (Object aYearSet : yearSet) { Date date = (Date) aYearSet; if (checkDate(cal, dateToCalendar(date))) { return true; } } return false; }
From source file:Main.java
public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.MONTH, monthOfYear - 1); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;/*from w w w. ja v a 2 s . c o m*/ }
From source file:Main.java
/** * @param date//from ww w.ja v a 2s .co m * @return Returns year of the argument date. */ private static String getYearFromDate(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return String.valueOf(cal.get(Calendar.YEAR)); }