Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:Main.java

/**
 * Get next month end day//from   w w  w.  j a  v a2  s . c  o  m
 *
 * @return
 */
public static int getNextMonthEndDay() {
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, 1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:models.Activation.java

public static Activation generateActivationCode(User u, int validForDays) {
    Activation a = new Activation();
    a.user = u;/*from  w  w w .j  a v a  2  s .com*/
    u.activation = a;
    a.activationCode = RandomStringUtils.randomAlphanumeric(40);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, validForDays);

    a.expirationDate = c.getTime();

    a.save();
    u.save();

    return a;
}

From source file:Main.java

private static Date getDateBefore() {
    Date nowtime = new Date();
    Calendar now = Calendar.getInstance();
    now.setTime(nowtime);//from  ww  w.jav  a  2  s  .  com
    now.set(Calendar.DATE, now.get(Calendar.DATE) - LOG_SAVE_DAYS);
    return now.getTime();
}

From source file:Main.java

public static Calendar calculateNextAlarmTime(int repetition) {
    if (repetition == 0)
        return null;
    Calendar alarmTime = Calendar.getInstance();
    alarmTime.set(Calendar.HOUR_OF_DAY, 20);
    alarmTime.set(Calendar.MINUTE, 0);
    alarmTime.set(Calendar.SECOND, 0);

    int day_of_week = alarmTime.get(Calendar.DAY_OF_WEEK) - 2;
    if (day_of_week == -1)
        day_of_week = 6;// sunday
    repetition &= 0x7f;//from ww w . ja  va2 s  .co  m
    int rot = (repetition >> (day_of_week + 1)) | (repetition << (7 - day_of_week - 1));
    rot &= 0x7f;
    int ndays = 0;
    for (ndays = 0; ndays < 7; ndays++) {
        if ((rot & (1 << ndays)) != 0)
            break;
    }
    alarmTime.add(Calendar.DATE, ndays + 1);

    return alarmTime;
}

From source file:Main.java

private static void populateDayRanges(Date start, Date end) {
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(start);//from w  w w  .j  a v  a2  s  .  co  m
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(end);

    sDayNames.clear();
    sDayAbbreviations.clear();

    for (Date date = startCal.getTime(); startCal.before(endCal); startCal.add(Calendar.DATE,
            1), date = startCal.getTime()) {
        sDayNames.add(dayLabelFormatter.format(date));
        sDayAbbreviations.add(dayAbbrevFormatter.format(date));
    }
}

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.jav a2  s .  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

private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;//  w ww . ja v a 2s.co m
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}

From source file:Main.java

public static Date getNextdayDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  www.j  ava  2s.  c  om
    calendar.add(Calendar.DATE, 1);
    return calendar.getTime();
}

From source file:Main.java

public static Date getLastdayDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from ww  w. j  a va  2  s . c o  m
    calendar.add(Calendar.DATE, -1);
    return calendar.getTime();
}

From source file:Main.java

public static boolean isCheckChangePermitted(Context context, Calendar date) {

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    String limitActivePref = sharedPrefs.getString("active-date-key", "ALLOW_ALL");

    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    Calendar yesterday;/*from   ww  w .j a v a  2s.  com*/

    switch (limitActivePref) {
    case "ALLOW_CURRENT":
        return (date.compareTo(today) == 0);
    case "ALLOW_CURRENT_AND_NEXT_DAY":
        yesterday = (Calendar) today.clone();
        yesterday.add(Calendar.DATE, -1);
        return (date.compareTo(yesterday) >= 0);
    case "ALLOW_CURRENT_AND_NEXT_DAY_AND_WEEKEND":
        yesterday = (Calendar) today.clone();
        yesterday.add(Calendar.DATE, today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY ? -2 : -1);
        return (date.compareTo(yesterday) >= 0);
    case "ALLOW_ALL":
    default:
        return true;
    }
}