Example usage for java.util Calendar MONTH

List of usage examples for java.util Calendar MONTH

Introduction

In this page you can find the example usage for java.util Calendar MONTH.

Prototype

int MONTH

To view the source code for java.util Calendar MONTH.

Click Source Link

Document

Field number for get and set indicating the month.

Usage

From source file:Main.java

public static double getJulDate() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    int second = cal.get(Calendar.SECOND);
    double extra = (100.0 * year) + month - 190002.5;
    double julianDay = (367.0 * year) - (Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0))
            + Math.floor((275.0 * month) / 9.0) + day + ((hour + ((minute + (second / 60.0)) / 60.0)) / 24.0)
            + 1721013.5 - ((0.5 * extra) / Math.abs(extra)) + 0.5;
    DecimalFormat sixDigitFormat = new DecimalFormat("#.######");
    return Double.valueOf(sixDigitFormat.format(julianDay));
}

From source file:Main.java

/**
 * Checks the calendar is tomorrow.//  w  w w  .j  a  v a 2s .c  o  m
 * @param calendar Calendar object to check.
 * @return true if calendar is tomorrow else false.
 */
public static boolean isTomorrow(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH)
            && calendar.get(Calendar.DAY_OF_MONTH) == (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1);
}

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 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  .  j a  va  2s .  co m
}

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;/*  w  w w.  j  a  va 2 s.c om*/
    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

public static boolean is1erMai(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.MAY && calendar.get(Calendar.DATE) == 1;
}

From source file:Main.java

public static Bundle bundleCalendar(Calendar cal, long minDate) {
    Bundle args = new Bundle();
    if (cal == null)
        cal = Calendar.getInstance(Locale.getDefault());
    ;//w  w w  . jav  a2 s .  c  o  m
    args.putInt("year", cal.get(Calendar.YEAR));
    args.putInt("month", cal.get(Calendar.MONTH));
    args.putInt("day", cal.get(Calendar.DAY_OF_MONTH));
    args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY));
    args.putInt("minute", cal.get(Calendar.MINUTE));
    args.putLong("minDate", minDate);
    return args;
}

From source file:Main.java

public static int compare(Calendar date1, Calendar date2) {
    int i = date1.get(Calendar.YEAR);
    int j = date2.get(Calendar.YEAR);

    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.MONTH);
    j = date2.get(Calendar.MONTH);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.DAY_OF_MONTH);
    j = date2.get(Calendar.DAY_OF_MONTH);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.HOUR_OF_DAY);
    j = date2.get(Calendar.HOUR_OF_DAY);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.MINUTE);
    j = date2.get(Calendar.MINUTE);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    i = date1.get(Calendar.SECOND);
    j = date2.get(Calendar.SECOND);
    if (i > j)
        return 1;
    if (i < j)
        return -1;

    return 0;/* ww w .j a va  2  s .c  o m*/
}

From source file:Main.java

public static boolean isTodayInCalendar(Calendar calendar) {
    return todayCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)
            && todayCalendar.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)
            && todayCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR);
}

From source file:Main.java

/**
 * Check the given date is February 29th.
 * @param calendar Calendar object to check
 * @return true if date is February 29th, else false.
 *///from   ww  w  . j  ava2  s .  c  o m
public static boolean isInsaneDate(Calendar calendar) {
    return calendar.get(Calendar.DAY_OF_MONTH) == 29 && calendar.get(Calendar.MONTH) == 1;
}