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

/**
 * Creates a calendar object with the next absolute time determined by hour and minute
 * @param hourOfDay/*from  w  w  w .  ja  v  a 2s .  co  m*/
 * @param minute
 * @return
 */
public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) {
    Calendar cal = Calendar.getInstance();
    Calendar calNow = (Calendar) cal.clone();

    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    if (cal.compareTo(calNow) <= 0) {
        //Today's time passed, count to tomorrow
        cal.add(Calendar.DATE, 1);
    }
    return cal;
}

From source file:com.dhenton9000.selenium.generic.UtilMethods.java

public static String getPreviousDate(int daysAgo) {
    DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy");
    newFormat.setLenient(true);/*w w  w .j  a  v a 2 s .c  o  m*/
    Calendar cal = Calendar.getInstance();
    cal.setTime(new java.util.Date());
    cal.add(Calendar.DATE, -1 * daysAgo);
    return newFormat.format(cal.getTime());
}

From source file:com.bjond.utilities.DateTimeUtils.java

/**
 * Returns 00:01:01.000 in the morning of Date.
 *
 * @param date Valid non-null java.util.Date object
 * @return New date. Original is not altered.
 *///from  w  ww .j  a v a2s  .c om
public static Date getStartOfDay(final Date date) {
    return DateUtils.truncate(date, Calendar.DATE);
}

From source file:Main.java

@NonNull
static Date convertDate(int date, int time) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 1997);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, time / 60);
    calendar.set(Calendar.MINUTE, time % 60);

    calendar.add(Calendar.DATE, date);

    return calendar.getTime();
}

From source file:Main.java

public DateIterator(Date start, Date end) {
    this.end.setTime(end);
    this.end.add(Calendar.DATE, -1);
    this.current.setTime(start);
    this.current.add(Calendar.DATE, -1);
}

From source file:com.its.web.services.DatesService.java

public int getRemainingDays(License license) {
    Date now = new Date();

    Calendar c = Calendar.getInstance();
    c.setTime(license.getStartDate());//from  ww  w  . j  a v  a 2 s  . c  o  m
    c.add(Calendar.DATE, license.getTrialPeriod());

    Date endTrialDate = c.getTime();

    int remainingDays = Days.daysBetween(new DateTime(now), new DateTime(endTrialDate)).getDays();

    return remainingDays;

}

From source file:com.taobao.tddl.sample.util.DateUtil.java

/**
 * /// w ww  .  j  a  va  2 s.  co  m
 *
 * @param intervals
 * @param format
 * @return
 */
public static String getDiffDate(int intervals, String format) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, intervals);
    Date intervalDay = cal.getTime();
    return formatDate(intervalDay, format);
}

From source file:Main.java

public static File getEmptyFileWithStructuredPath(String course_title, String format) {
    Calendar calendar = Calendar.getInstance();
    int date = calendar.get(Calendar.DATE);
    int month = calendar.get(Calendar.MONTH) + 1;
    int year = calendar.get(Calendar.YEAR);
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);

    StringBuffer dateInString = new StringBuffer();
    dateInString.append(month);//from   w ww .  ja  v  a2  s  .  co  m
    dateInString.append("-");
    dateInString.append(date);
    dateInString.append("-");
    dateInString.append(year);
    StringBuffer timeInString = new StringBuffer();
    timeInString.append(hour);
    timeInString.append("_");
    timeInString.append(minute);
    timeInString.append("_");
    timeInString.append(second);
    Log.d("File Storage", "DateTime : " + dateInString + timeInString);

    String folderPathInString = Environment.getExternalStorageDirectory().toString() + "/" + LECTURE_HELPER
            + "/" + course_title + "/" + dateInString + "/";

    File folderPath = new File(folderPathInString);
    if (!folderPath.exists()) {
        folderPath.mkdirs();
    }

    return new File(folderPath.getPath() + "/" + FILE_NAME_TO_SAVE + timeInString + format);

}

From source file:cn.mypandora.util.MyDateUtils.java

/**
 * ?.//w  ww  .j a v  a  2 s . com
 *
 * @return
 */
public static String getMonthFirstDay() {
    Calendar cal = Calendar.getInstance();
    // ,?.
    // Calendar f = (Calendar) cal.clone();
    // f.clear();
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH));
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DATE));
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // .
    cal.set(Calendar.DATE, 1);
    return DateFormatUtils.format(cal, DATE_FORMAT);

}

From source file:Main.java

/**
 * Using the expiry date, generate the application end date in the correct format.
 *
 * @param expiryMonth Month of expiry.//from  w  w w  .  j a va  2s  .c  o m
 * @param expiryYear  Year of expiry.
 * @return The application end date in the correct format.
 */
private static String generateExpiryDate(String expiryMonth, String expiryYear) {
    // Just combine the year and month
    String applicationEndDate = expiryYear + expiryMonth;

    // Now need to work out the last day of the month
    // NB: Calendar's months range from 0-11 rather than 1-12
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, Integer.parseInt(expiryYear));
    calendar.set(Calendar.MONTH, Integer.parseInt(expiryMonth) - 1);
    applicationEndDate += calendar.getActualMaximum(Calendar.DATE);

    return applicationEndDate;
}