Example usage for java.util Calendar MINUTE

List of usage examples for java.util Calendar MINUTE

Introduction

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

Prototype

int MINUTE

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

Click Source Link

Document

Field number for get and set indicating the minute within the hour.

Usage

From source file:fll.web.report.finalist.FinalistDBRow.java

@JsonIgnore
public Date getTime() {
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR, getHour());
    cal.set(Calendar.MINUTE, getMinute());
    cal.set(Calendar.SECOND, 0);//from   w  w w .j a va2s.  co m
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTime();
}

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  ww w. j a  va 2 s. 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:Main.java

/**
 * Add date time with one minute./*from   w  w w . ja  va 2 s . com*/
 *
 * @param listing     the listing
 * @param currentTime the current time
 * @param isPast      true/false if past time
 */
private static void addDateTimeWithOneMinute(final List<Long> listing, final long currentTime,
        final boolean isPast) {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    if (isPast) {
        calendar.add(Calendar.MINUTE, -1);
    } else {
        calendar.add(Calendar.SECOND, 62);
    }
    listing.add(calendar.getTimeInMillis());
}

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

/**
 * ??//from   w  ww  .  ja v  a 2 s  .  c om
 * @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: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);
   cal.set(Calendar.SECOND, 0);/* www  .j av a 2 s.com*/
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:Main.java

/**
 * Adds a number of minutes to a date returning a new object.
 * The original date object is unchanged.
 *
 * @param date  the date, not null//  w  ww  . jav  a2  s.co m
 * @param amount  the amount to add, may be negative
 * @return the new date object with the amount added
 * @throws IllegalArgumentException if the date is null
 */
public static Date addMinutes(Date date, int amount) {
    return add(date, Calendar.MINUTE, amount);
}

From source file:Main.java

/**
 * Sets the minute field to a date returning a new object.
 * The original date object is unchanged.
 *
 * @param date  the date, not null//from w ww  . j  a  v  a2 s .  com
 * @param amount the amount to set
 * @return a new Date object set with the specified value
 * @throws IllegalArgumentException if the date is null
 * @since 2.4
 */
public static Date setMinutes(Date date, int amount) {
    return set(date, Calendar.MINUTE, amount);
}

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 a v a 2s .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:TimeUtil.java

/**
 * convert time in milliseconds into a display string of the form [h]h:mm
 * [am|pm] (traditional) or hh:mm (24 hour format) if using traditional
 * format, the leading 'h' & 'm' will be padded with a space to ensure
 * constant length if less than 10 24 hour format
 * //  w w w .j a v a2s . c o  m
 * @param msecs
 *            a millisecond time
 * @return TimeString the formatted time string
 */
public static String stringFormat(long msecs) {
    GregorianCalendar cal = new GregorianCalendar();
    StringBuffer sBuf = new StringBuffer(8);

    cal.setTime(new Date(msecs));

    int hour = cal.get(Calendar.HOUR);

    if (hour == 0)
        hour = 12;

    if (hour < 10)
        sBuf.append(" ");

    sBuf.append(Integer.toString(hour));
    sBuf.append(":");

    int minute = cal.get(Calendar.MINUTE);

    if (minute < 10)
        sBuf.append("0");

    sBuf.append(Integer.toString(minute));
    sBuf.append(" ");
    sBuf.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM");

    return (sBuf.toString());
}