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:com.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);// ww w  . ja  va2s  .  c o  m
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MONTH) + 1));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.DATE)));
    date.append(Constants.DateFormatter.DATE_DELIM);
    date.append(padSingleDigitNum(cal.get(Calendar.HOUR)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MINUTE)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.SECOND)));
    date.append(Constants.DateFormatter.TIME_DELIM);
    return date.toString();
}

From source file:com.glaf.core.util.CalendarUtils.java

/**
 * ?// w ww  .ja va2s. c om
 * 
 * @param date
 * @param day
 * @return
 */
private static Date getDateAfter(Date date, int day) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) + day);
    return cal.getTime();
}

From source file:DateUtils.java

/**
 * Get unix style date string.// www  .  j  a va 2  s.c  o m
 */
public final static String getUnixDate(long millis) {
    if (millis < 0) {
        return "------------";
    }

    StringBuffer sb = new StringBuffer(16);
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(millis);

    // month
    sb.append(MONTHS[cal.get(Calendar.MONTH)]);
    sb.append(' ');

    // day
    int day = cal.get(Calendar.DATE);
    if (day < 10) {
        sb.append(' ');
    }
    sb.append(day);
    sb.append(' ');

    long sixMonth = 15811200000L; // 183L * 24L * 60L * 60L * 1000L;
    long nowTime = System.currentTimeMillis();
    if (Math.abs(nowTime - millis) > sixMonth) {

        // year
        int year = cal.get(Calendar.YEAR);
        sb.append(' ');
        sb.append(year);
    } else {

        // hour
        int hh = cal.get(Calendar.HOUR_OF_DAY);
        if (hh < 10) {
            sb.append('0');
        }
        sb.append(hh);
        sb.append(':');

        // minute
        int mm = cal.get(Calendar.MINUTE);
        if (mm < 10) {
            sb.append('0');
        }
        sb.append(mm);
    }
    return sb.toString();
}

From source file:gov.utah.dts.det.ccl.model.FacilityTest.java

@Test
public void testGetLatestLicense() {
    Date now = DateUtils.truncate(new Date(), Calendar.DATE);
    Facility f1 = new Facility();

    //null should be returned when the facility has no license
    assertNull(f1.getLatestLicense());//from  w  w  w  .ja  v a 2 s.  co m

    //future licenses should not be returned
    License l2 = new License();
    l2.setStartDate(DateUtils.addDays(now, 30));
    l2.setExpirationDate(DateUtils.addDays(now, 60));

    //licenses that have expired should be returned
    License l3 = new License();
    l3.setStartDate(DateUtils.addDays(now, -60));
    l3.setExpirationDate(DateUtils.addDays(now, -30));
    f1.addLicense(l3);
    assertEquals(f1.getLatestLicense(), l3);

    //current licenses should be returned
    License l4 = new License();
    l4.setStartDate(DateUtils.addDays(now, -29));
    l4.setExpirationDate(DateUtils.addDays(now, 29));
    f1.addLicense(l4);
    assertEquals(f1.getLatestLicense(), l4);
}

From source file:ar.com.zauber.commons.secret.impl.DaysExpirationDatePolicy.java

/** @see ExpirationDatePolicy#getExpirationDate(Guest) */
public final Date getExpirationDate(final T t) {
    Calendar date = Calendar.getInstance();
    date.add(Calendar.DATE, days);

    return date.getTime();
}

From source file:net.sf.ipsedixit.integration.extension.AnnotatedClassAddCustomHandlerIntegrationTest.java

@Test
public void hasWorked() {
    assertThat(stubDate.toString(),/*from   ww w . j  av  a  2  s . c  om*/
            Matchers.containsString("Proxy for java.util.Date defined by field stubDate"));
    Date todaysDate = truncate(new Date(), Calendar.DATE);
    assertThat(today.getTime(), equalTo(todaysDate.getTime()));
}

From source file:net.sf.ipsedixit.integration.junit.v3.AnnotatedClassAddCustomHandlerIntegrationTest.java

public void testHasWorked() {
    assertThat(stubDate.toString(),/*from w  w w. ja v a 2  s .  co m*/
            Matchers.containsString("Proxy for java.util.Date defined by field stubDate"));
    Date todaysDate = truncate(new Date(), Calendar.DATE);
    assertThat(today.getTime(), equalTo(todaysDate.getTime()));
}

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

/**
 * ??//from   ww  w  . j  a  v  a2  s.  co m
 *
 * @return
 */
public static String getMonthLastDay() {
    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) + 1);
    // f.set(Calendar.MILLISECOND, -1);
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // 
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH));
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // (?)
    cal.set(Calendar.DATE, 1);// ?1?
    cal.add(Calendar.MONTH, 1);// ?1?
    cal.add(Calendar.DATE, -1);// ???
    return DateFormatUtils.format(cal, DATE_FORMAT);
}

From source file:co.mafiagame.engine.util.PurgeTimer.java

@PostConstruct
public void initPurgeTimer() {
    Calendar now = Calendar.getInstance();
    now.add(Calendar.SECOND, 10);
    now.add(Calendar.DATE, 1);
    now.set(Calendar.HOUR_OF_DAY, 6);
    Timer timer = new Timer();
    timer.schedule(this, now.getTime(), 24 * 60 * 60 * 1000);
}

From source file:com.erpbi.GetDateInfo.java

public Object execute(Evaluator evaluator, Argument[] arguments) {
    synchronized (this) {
        if (udfName.equals("getDateString")) {
            // get input string as int
            Object oDays = arguments[0].evaluate(evaluator);
            String sDays = oDays.toString();
            float fDays = Float.parseFloat(sDays);
            int iDays = (int) fDays;
            // create Calendar starting at 1900/01/01 and bump by input days
            Calendar c = Calendar.getInstance();
            c.set(1900, 00, 01);//from   w  ww  .j  av a  2  s.  c  o  m
            c.add(Calendar.DATE, iDays);

            // format date string
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            returnString = sdf.format(c.getTime());
        } else if (udfName.equals("getCurrentDays")) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            Date today = new Date();
            long d1 = 0;

            try {
                d1 = sdf.parse("1900/01/01").getTime();
            } catch (Exception e) {
                e.printStackTrace(System.out);
            }
            long d2 = today.getTime();

            returnString = "" + Math.abs((d2 - d1) / (1000 * 60 * 60 * 24));
        } else {
            returnString = "";
        }

        if (log.isDebugEnabled()) {
            log.debug(" returnString: " + returnString);
        }

        return returnString;
    }
}