Example usage for java.util Calendar MILLISECOND

List of usage examples for java.util Calendar MILLISECOND

Introduction

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

Prototype

int MILLISECOND

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

Click Source Link

Document

Field number for get and set indicating the millisecond within the second.

Usage

From source file:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar getCalendar(String yyyy, String mm, String dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, Integer.valueOf(yyyy));
   cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1);
   cal.set(Calendar.DATE, Integer.valueOf(dd));
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);//from   w w w .  j  a va2  s. c o  m
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:com.liusoft.dlog4j.util.DateUtils.java

/**
 * ??//from w  w  w .  j av a2  s  .c  o m
 * @param year
 * @param month
 * @param date
 * @return
 */
public static Calendar getDateBegin(int year, int month, int date) {
    Calendar begin_time = Calendar.getInstance();
    begin_time.set(Calendar.YEAR, year);
    begin_time.set(Calendar.MONTH, month - 1);
    begin_time.set(Calendar.DATE, date);
    begin_time.set(Calendar.HOUR_OF_DAY, 0);
    begin_time.set(Calendar.MINUTE, 0);
    begin_time.set(Calendar.SECOND, 0);
    begin_time.set(Calendar.MILLISECOND, 0);
    return begin_time;
}

From source file:mojo.core.test.BaseTest.java

protected static Date createDateTime(int year, int month, int day, int hour, int minute, int second) {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.set(year, month, day, hour, minute, second);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

From source file:thymeleafsandbox.springjsp.web.controller.jsp.JspForm.java

@ModelAttribute("user")
public User populateUser() {
    final User user = new User();
    final Calendar registrationDate = Calendar.getInstance();
    registrationDate.set(Calendar.MILLISECOND, 0);
    registrationDate.set(Calendar.SECOND, 0);
    registrationDate.set(Calendar.MINUTE, 0);
    registrationDate.set(Calendar.HOUR, 0);
    user.setId(Integer.valueOf(12345));
    user.setRegistrationDate(registrationDate);
    user.setActive(Boolean.TRUE);
    user.setMultiValues(new ArrayList<String>(Arrays.asList(new String[] { "TWO", "FOUR" })));
    return user;//from  w w  w.ja  v a2 s . com
}

From source file:Main.java

private static GregorianCalendar gmtStringToGregorianCalendar(String stringTypeDate)
        throws DatatypeConfigurationException {
    String yyyy = stringTypeDate.substring(0, 4);
    String mm = stringTypeDate.substring(5, 7);
    String dd = stringTypeDate.substring(8, 10);

    String hh = "00";
    String mi = "00";
    String ss = "00";
    String ms = "00";
    String tz = null;/*from ww w  .  j  a  v a  2 s  .  c o m*/

    if (stringTypeDate.length() > 23) {
        hh = stringTypeDate.substring(11, 13);
        mi = stringTypeDate.substring(14, 16);
        ss = stringTypeDate.substring(17, 19);
        ms = stringTypeDate.substring(20, 23);
        tz = stringTypeDate.substring(23);
    } else {
        tz = stringTypeDate.substring(10);
        //tz = "+09:00";
    }

    if (tz.equals("Z")) {
        tz = "UTC";
    } else {
        tz = "GMT" + tz;
    }

    int iyyyy = Integer.parseInt(yyyy);
    int imm = Integer.parseInt(mm) - 1;
    int idd = Integer.parseInt(dd);
    int ihh = Integer.parseInt(hh);
    int imi = Integer.parseInt(mi);
    int iss = Integer.parseInt(ss);
    int ims = Integer.parseInt(ms);

    Calendar c = Calendar.getInstance();
    c.setTimeZone(TimeZone.getTimeZone(tz));
    c.set(iyyyy, imm, idd, ihh, imi, iss);
    c.set(Calendar.MILLISECOND, ims);

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(c.getTime());
    cal.setTimeZone(TimeZone.getTimeZone("ROK"));

    return cal;
}

From source file:net.audumla.climate.bom.ObserverTest.java

@Test
public void testObservations() {
    Calendar c = GregorianCalendar.getInstance();
    c.setTime(new Date());
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.SECOND, 0);//w ww.java2 s  .c om
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 1);
    Date now = c.getTime();
    BOMClimateDataSource source = ClimateDataSourceFactory.newInstance(BOMClimateDataSource.class);
    source.setId("086068");
    ClimateObserver forcaster = new BOMPeriodicClimateObserver(source);
    ClimateData data = forcaster.getClimateData(now);
    Assert.assertEquals(now, data.getTime());
    // Assert.assertNotNull(data.getMinimumTemperature());
    c.set(Calendar.HOUR_OF_DAY, 12);
    Date obTime1 = c.getTime();
    ClimateObservation obs1 = data.getObservation(obTime1, ClimateData.ObservationMatch.CLOSEST);
    Assert.assertNotNull(obs1);
    Assert.assertNotNull(obs1.getTemperature());
    c.set(Calendar.HOUR_OF_DAY, 11);
    Date obTime2 = c.getTime();
    ClimateObservation obs2 = data.getObservation(obTime2, ClimateData.ObservationMatch.CLOSEST);
    Assert.assertNotNull(obs2);
    Assert.assertNotNull(obs2.getTemperature());
    Assert.assertNotSame(obs1.getTime(), obs2.getTime());

}

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());/*from  w  w  w.  j  ava  2  s.co m*/
    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:com.nexmo.client.voice.CallsFilterTest.java

@Test
public void testAllParams() {
    /*//from  w  ww.  ja  v  a  2s . c  o m
    private Integer recordIndex;
    private String order;
     */

    Calendar startCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    startCalendar.set(2016, Calendar.JANUARY, 1, 7, 8, 20);
    startCalendar.set(Calendar.MILLISECOND, 0);
    Date startDate = startCalendar.getTime();
    Calendar endCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    endCalendar.set(2016, Calendar.JANUARY, 1, 7, 8, 55);
    endCalendar.set(Calendar.MILLISECOND, 0);
    Date endDate = endCalendar.getTime();

    CallsFilter filter = new CallsFilter();
    filter.setStatus(CallStatus.COMPLETED);
    filter.setDateStart(startDate);
    filter.setDateEnd(endDate);
    filter.setRecordIndex(12);
    filter.setOrder("asc");
    filter.setPageSize(10);
    filter.setConversationUuid("this-is-not-a-uuid");

    assertEquals(CallStatus.COMPLETED, filter.getStatus());
    assertEquals(startDate, filter.getDateStart());
    assertEquals(endDate, filter.getDateEnd());
    assertEquals(12, (int) filter.getRecordIndex());
    assertEquals("asc", filter.getOrder());
    assertEquals(10, (int) filter.getPageSize());
    assertEquals("this-is-not-a-uuid", filter.getConversationUuid());

    List<NameValuePair> params = filter.toUrlParams();
    Map<String, String> paramLookup = new HashMap<String, String>();
    for (NameValuePair pair : params) {
        paramLookup.put(pair.getName(), pair.getValue());
    }

    assertEquals("completed", paramLookup.get("status"));
    assertEquals("2016-01-01T07:08:55Z", paramLookup.get("date_end"));
    assertEquals("2016-01-01T07:08:20Z", paramLookup.get("date_start"));
    assertEquals("12", paramLookup.get("record_index"));
    assertEquals("asc", paramLookup.get("order"));
    assertEquals("10", paramLookup.get("page_size"));
    assertEquals("this-is-not-a-uuid", paramLookup.get("conversation_uuid"));
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

public static Date convertDateToTimeZone(Date date, String toTimeZone) {
    Calendar toCal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone));
    Calendar fromCal = new GregorianCalendar();
    fromCal.setTime(date);//from  w ww.ja  v  a2  s.c om

    toCal.set(fromCal.get(Calendar.YEAR), fromCal.get(Calendar.MONTH), fromCal.get(Calendar.DAY_OF_MONTH),
            fromCal.get(Calendar.HOUR_OF_DAY), fromCal.get(Calendar.MINUTE), fromCal.get(Calendar.SECOND));
    toCal.set(Calendar.MILLISECOND, fromCal.get(Calendar.MILLISECOND));

    return toCal.getTime();
}

From source file:DateParser.java

private static Calendar getCalendar(String isodate) {
    // YYYY-MM-DDThh:mm:ss.sTZD
    StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true);

    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.clear();//from  ww w  .  j a  v  a2  s  . co m
    try {
        // Year
        if (st.hasMoreTokens()) {
            int year = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.YEAR, year);
        } else {
            return calendar;
        }
        // Month
        if (check(st, "-") && (st.hasMoreTokens())) {
            int month = Integer.parseInt(st.nextToken()) - 1;
            calendar.set(Calendar.MONTH, month);
        } else {
            return calendar;
        }
        // Day
        if (check(st, "-") && (st.hasMoreTokens())) {
            int day = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.DAY_OF_MONTH, day);
        } else {
            return calendar;
        }
        // Hour
        if (check(st, "T") && (st.hasMoreTokens())) {
            int hour = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.HOUR_OF_DAY, hour);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        // Minutes
        if (check(st, ":") && (st.hasMoreTokens())) {
            int minutes = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.MINUTE, minutes);
        } else {
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }

        //
        // Not mandatory now
        //

        // Secondes
        if (!st.hasMoreTokens()) {
            return calendar;
        }
        String tok = st.nextToken();
        if (tok.equals(":")) { // secondes
            if (st.hasMoreTokens()) {
                int secondes = Integer.parseInt(st.nextToken());
                calendar.set(Calendar.SECOND, secondes);
                if (!st.hasMoreTokens()) {
                    return calendar;
                }
                // frac sec
                tok = st.nextToken();
                if (tok.equals(".")) {
                    // bug fixed, thx to Martin Bottcher
                    String nt = st.nextToken();
                    while (nt.length() < 3) {
                        nt += "0";
                    }
                    nt = nt.substring(0, 3); // Cut trailing chars..
                    int millisec = Integer.parseInt(nt);
                    // int millisec = Integer.parseInt(st.nextToken()) * 10;
                    calendar.set(Calendar.MILLISECOND, millisec);
                    if (!st.hasMoreTokens()) {
                        return calendar;
                    }
                    tok = st.nextToken();
                } else {
                    calendar.set(Calendar.MILLISECOND, 0);
                }
            } else {
                throw new RuntimeException("No secondes specified");
            }
        } else {
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        }
        // Timezone
        if (!tok.equals("Z")) { // UTC
            if (!(tok.equals("+") || tok.equals("-"))) {
                throw new RuntimeException("only Z, + or - allowed");
            }
            boolean plus = tok.equals("+");
            if (!st.hasMoreTokens()) {
                throw new RuntimeException("Missing hour field");
            }
            int tzhour = Integer.parseInt(st.nextToken());
            int tzmin = 0;
            if (check(st, ":") && (st.hasMoreTokens())) {
                tzmin = Integer.parseInt(st.nextToken());
            } else {
                throw new RuntimeException("Missing minute field");
            }
            if (plus) {
                calendar.add(Calendar.HOUR, -tzhour);
                calendar.add(Calendar.MINUTE, -tzmin);
            } else {
                calendar.add(Calendar.HOUR, tzhour);
                calendar.add(Calendar.MINUTE, tzmin);
            }
        }
    } catch (NumberFormatException ex) {
        throw new RuntimeException("[" + ex.getMessage() + "] is not an integer");
    }
    return calendar;
}