Example usage for java.util Calendar DAY_OF_MONTH

List of usage examples for java.util Calendar DAY_OF_MONTH

Introduction

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

Prototype

int DAY_OF_MONTH

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static Date getDateTimeFrom(Date time, Date date) {
    Date iTime, iDate;// w w w  .j  a  va 2s.  c  om
    Calendar calendar = Calendar.getInstance();

    if (date == null) {
        iTime = time;
        iDate = new Date();
    } else {
        iTime = time;
        iDate = date;
    }

    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(iDate);

    Calendar calendarTime = Calendar.getInstance();
    if (iTime != null)
        calendarTime.setTime(iTime);

    if (iTime != null) {
        calendar.set(Calendar.MINUTE, calendarTime.get(Calendar.MINUTE));
        calendar.set(Calendar.HOUR_OF_DAY, calendarTime.get(Calendar.HOUR_OF_DAY));
    } else {
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
    }

    //calendar.set(Calendar.AM_PM, calendarTime.get(Calendar.AM_PM) );

    calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.MONTH, calendarDate.get(Calendar.MONTH));
    calendar.set(Calendar.YEAR, calendarDate.get(Calendar.YEAR));

    Date ret = calendar.getTime();
    Log.v("!!!!!!!!!! calendar=", "" + ret);

    return ret;
}

From source file:ar.com.zauber.commons.date.SignificantDateProviderTest.java

/** dia del mes */
@Test//w ww .  j a v  a  2 s  .co m
public final void testDay() {
    final DateProvider provider = new SignificantDateProvider(target, Calendar.DAY_OF_MONTH);
    Assert.assertEquals(DateUtils.truncate(new Date(1269028059L * 1000), Calendar.DAY_OF_MONTH),
            provider.getDate());
}

From source file:com.webbfontaine.valuewebb.model.validators.MpPriceDateValidator.java

public static boolean validate(Date date) {
    Date todayDate = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Date dateWithoutTime = DateUtils.truncate(date, Calendar.DAY_OF_MONTH);

    return date == null || Integer.parseInt(new SimpleDateFormat("yyyy").format(date)) >= 2010
            && !todayDate.before(dateWithoutTime);
}

From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java

public static Long createCycle(ZephyrConfigModel zephyrData) {

    Long cycleId = 0L;/*  w  w w.  j av  a 2  s  . c  o  m*/

    HttpResponse response = null;
    try {
        String createCycleURL = URL_CREATE_CYCLES.replace("{SERVER}", zephyrData.getRestClient().getUrl());

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("E dd, yyyy hh:mm a");
        String dateFormatForCycleCreation = sdf.format(date);

        JSONObject jObject = new JSONObject();
        String cycleName = zephyrData.getCyclePrefix() + dateFormatForCycleCreation;

        SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MMM/yy");
        String startDate = sdf1.format(date);

        GregorianCalendar gCal = new GregorianCalendar();

        if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("30 days")) {
            gCal.add(Calendar.DAY_OF_MONTH, +29);
        } else if (zephyrData.getCycleDuration().trim().equalsIgnoreCase("7 days")) {
            gCal.add(Calendar.DAY_OF_MONTH, +6);
        }

        String endDate = sdf1.format(gCal.getTime());

        jObject.put("name", cycleName);
        jObject.put("projectId", zephyrData.getZephyrProjectId());
        jObject.put("versionId", zephyrData.getVersionId());
        jObject.put("startDate", startDate);
        jObject.put("endDate", endDate);

        StringEntity se = new StringEntity(jObject.toString(), "utf-8");

        HttpPost createCycleRequest = new HttpPost(createCycleURL);

        createCycleRequest.setHeader("Content-Type", "application/json");
        createCycleRequest.setEntity(se);
        response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest,
                zephyrData.getRestClient().getContext());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode >= 200 && statusCode < 300) {
        HttpEntity entity = response.getEntity();
        String string = null;
        try {
            string = EntityUtils.toString(entity);
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            JSONObject cycleObj = new JSONObject(string);
            cycleId = cycleObj.getLong("id");

        } catch (JSONException e) {
            e.printStackTrace();
        }

    } else if (statusCode == 405) {

        try {
            throw new ClientProtocolException("ZAPI plugin license is invalid" + statusCode);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        }

    } else {
        try {
            throw new ClientProtocolException("Unexpected response status: " + statusCode);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        }
    }

    return cycleId;
}

From source file:facebook4j.internal.util.z_F4JInternalStringUtilTest.java

@Test
public void formatISO8601Datetime() throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2012);
    cal.set(Calendar.MONTH, 5);//from  w  w w. j  a v a  2s .  c  om
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR_OF_DAY, 16);
    cal.set(Calendar.MINUTE, 17);
    cal.set(Calendar.SECOND, 18);
    cal.set(Calendar.MILLISECOND, 0);

    cal.setTimeZone(TimeZone.getTimeZone("JST"));
    String actual1 = z_F4JInternalStringUtil.formatISO8601Datetime(cal);
    assertThat(actual1, is("2012-06-15T16:17:18+0900"));

    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    String actual2 = z_F4JInternalStringUtil.formatISO8601Datetime(cal);
    assertThat(actual2, is("2012-06-15T07:17:18+0000")); //16-9=7

    JSONObject json = new JSONObject(
            "{\"datetime1\": \"" + actual1 + "\", \"datetime2\": \"" + actual2 + "\"}");
    Date d1 = z_F4JInternalParseUtil.getISO8601Datetime("datetime1", json);
    Date d2 = z_F4JInternalParseUtil.getISO8601Datetime("datetime2", json);
    assertThat(d1, is(d2));
}

From source file:Main.java

private static String getCurrentTime() {
    Calendar calendar = Calendar.getInstance();
    String strTime = String.format("%4d-%02d-%02d %02d:%02d:%02d", calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
            calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
    return strTime;
}

From source file:fr.xebia.demo.objectgrid.ticketing.TrainSearchAgentTest.java

public void test() throws Exception {

    Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
    Date noonToday = DateUtils.addHours(today, 12);

    TrainSearchAgent trainSearchAgent = new TrainSearchAgent(PARIS_GARE_DE_LYON, noonToday,
            MARSEILLE_SAINT_CHARLES);// w  w w.  j  ava2 s .  com

    Session session = objectGrid.getSession();
    ObjectMap employeeMap = session.getMap("Train");
    AgentManager agentManager = employeeMap.getAgentManager();

    List<RouteDetails> matchingTrainsByPartionId = (List<RouteDetails>) agentManager
            .callReduceAgent(trainSearchAgent);
    logger.debug(matchingTrainsByPartionId.size() + " matching trains found ");

    for (RouteDetails routeDetails : matchingTrainsByPartionId) {
        logger.debug(routeDetails);
    }
}

From source file:com.livinglogic.ul4.FunctionAsJSON.java

private static void call(StringBuilder builder, Object obj) {
    if (obj == null)
        builder.append("null");
    else if (obj instanceof Boolean)
        builder.append(((Boolean) obj).booleanValue() ? "true" : "false");
    else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long
            || obj instanceof BigInteger || obj instanceof Double || obj instanceof Float)
        builder.append(obj.toString());// w ww .  j a  v  a2s.com
    else if (obj instanceof BigDecimal) {
        String result = obj.toString();
        builder.append(result);
        if (result.indexOf('.') < 0 || result.indexOf('E') < 0 || result.indexOf('e') < 0)
            builder.append(".0");
    } else if (obj instanceof String)
        builder.append("\"")
                // We're using StringEscapeUtils.escapeJava() here, which is the same as escapeJavaScript, except that it doesn't escape ' (which is illegal in JSON strings according to json.org)
                .append(StringEscapeUtils.escapeJava(((String) obj))).append("\"");
    else if (obj instanceof Date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime((Date) obj);
        builder.append("new Date(").append(calendar.get(Calendar.YEAR)).append(", ")
                .append(calendar.get(Calendar.MONTH)).append(", ").append(calendar.get(Calendar.DAY_OF_MONTH))
                .append(", ").append(calendar.get(Calendar.HOUR_OF_DAY)).append(", ")
                .append(calendar.get(Calendar.MINUTE)).append(", ").append(calendar.get(Calendar.SECOND));
        int milliSeconds = calendar.get(Calendar.MILLISECOND);
        if (milliSeconds != 0) {
            builder.append(", ").append(milliSeconds);
        }
        builder.append(")");
    } else if (obj instanceof InterpretedTemplate) {
        builder.append("ul4.Template.loads(\"")
                .append(StringEscapeUtils.escapeJavaScript(((InterpretedTemplate) obj).dumps())).append("\")");
    } else if (obj instanceof TemplateClosure) {
        builder.append("ul4.Template.loads(\"")
                .append(StringEscapeUtils.escapeJavaScript(((TemplateClosure) obj).getTemplate().dumps()))
                .append("\")");
    } else if (obj instanceof UL4Attributes) {
        builder.append("{");
        boolean first = true;
        Set<String> attributeNames = ((UL4Attributes) obj).getAttributeNamesUL4();
        for (String attributeName : attributeNames) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, attributeName);
            builder.append(": ");
            Object value = ((UL4Attributes) obj).getItemStringUL4(attributeName);
            call(builder, value);
        }
        builder.append("}");
    } else if (obj instanceof Color) {
        Color c = (Color) obj;
        builder.append("ul4.Color.create(").append(c.getR()).append(", ").append(c.getG()).append(", ")
                .append(c.getB()).append(", ").append(c.getA()).append(")");
    } else if (obj instanceof Collection) {
        builder.append("[");
        boolean first = true;
        for (Object o : (Collection) obj) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, o);
        }
        builder.append("]");
    } else if (obj instanceof Object[]) {
        builder.append("[");
        boolean first = true;
        for (Object o : (Object[]) obj) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, o);
        }
        builder.append("]");
    } else if (obj instanceof Map) {
        builder.append("{");
        boolean first = true;
        Set<Map.Entry> entrySet = ((Map) obj).entrySet();
        for (Map.Entry entry : entrySet) {
            if (first)
                first = false;
            else
                builder.append(", ");
            call(builder, entry.getKey());
            builder.append(": ");
            call(builder, entry.getValue());
        }
        builder.append("}");
    }
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);//from w  w  w .  j  a  v a2s.c  om

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:com.alibaba.utils.date.CommonDateUtils.java

/**
 * <pre>/*www  . j  a v  a  2 s  .c  om*/
 * 
 * 
 * 2013.09.20,2
 * 2013.09.20 2013.09.21 2013.09.22
 * </pre>
 * @param currentDate
 * @param days
 * @return
 */
public static List<Date> afterCurrentDate(Date currentDate, int days) {
    List<Date> dateList = new ArrayList<Date>();
    // 0. 
    if (currentDate == null) {
        return null;
    }
    if (days <= 0) {
        dateList.add(DateUtils.truncate(currentDate, Calendar.DAY_OF_MONTH));
        return dateList;
    }

    // 1. 
    Date startDate = new Date(currentDate.getTime());
    for (int i = 0; i <= days; ++i) {
        Date date = DateUtils.addDays(startDate, i);
        dateList.add(DateUtils.truncate(date, Calendar.DAY_OF_MONTH));
    }

    return dateList;
}