Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

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

Usage

From source file:es.tekniker.framework.ktek.util.Utils.java

public static long getTimeinMillis4TimeGMT(int hours, int minutes, int seconds) {
    Calendar c = getCalendarGMT();
    System.out.println("current: " + c.getTime());

    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);
    c.set(Calendar.SECOND, seconds);

    System.out.println("GMT Time: " + c.getTime());

    long timeinmillis = c.getTimeInMillis();
    System.out.println(" system time in millis " + timeinmillis);

    return timeinmillis;
}

From source file:AIR.Common.Utilities.Dates.java

/**
 * @param date/* www .ja  v  a 2s .  c  o m*/
 * @return returns the midnight time for before date ends e.g. if date is
 *         "10/11/2012 12:10 pm" then this will return "10/11/2012 11:59 pm"
 */
public static Date getEndOfDayDate(Date date) {
    Calendar calendarInstance = Calendar.getInstance();
    calendarInstance.setTime(date);
    calendarInstance.set(Calendar.HOUR_OF_DAY, 23);
    calendarInstance.set(Calendar.MINUTE, 59);
    calendarInstance.set(Calendar.SECOND, 0);
    return calendarInstance.getTime();
}

From source file:net.groupbuy.controller.admin.SalesRankingController.java

/**
 * //w ww.ja  v a 2 s. c o m
 */
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Date beginDate, Date endDate, Integer count, Model model) {
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (count == null || count <= 0) {
        count = DEFAULT_COUNT;
    }
    model.addAttribute("beginDate", beginDate);
    model.addAttribute("endDate", endDate);
    model.addAttribute("count", count);
    model.addAttribute("data", productService.findSalesList(beginDate, endDate, count));
    return "/admin/sales_ranking/list";
}

From source file:net.groupbuy.controller.admin.PurchaseRankingController.java

/**
 * //from   ww  w .j  av a 2 s .c o m
 */
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Date beginDate, Date endDate, Integer count, Model model) {
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        endDate = calendar.getTime();
    }
    if (count == null || count <= 0) {
        count = DEFAULT_COUNT;
    }
    model.addAttribute("beginDate", beginDate);
    model.addAttribute("endDate", endDate);
    model.addAttribute("count", count);
    model.addAttribute("data", memberService.findPurchaseList(beginDate, endDate, count));
    return "/admin/purchase_ranking/list";
}

From source file:com.aw.core.db.DbUtil.java

public boolean hasOnlyDateInfo(Date date) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);//from  ww w  .  j a v  a  2 s. c  o m
    if (cal.get(Calendar.HOUR_OF_DAY) != 0)
        return false;
    if (cal.get(Calendar.MINUTE) != 0)
        return false;
    if (cal.get(Calendar.SECOND) != 0)
        return false;
    if (cal.get(Calendar.MILLISECOND) != 0)
        return false;
    return true;
}

From source file:cat.albirar.framework.utilities.DatesUtilities.java

/**
 * Compare two date+time, with care of null. The information bellow second part of time are ignored. A null value is
 * considered less than any non-null value.
 * /*w w  w  .  j ava  2s  .  c  om*/
 * @param d1 The first date+time
 * @param d2 The second date+time
 * @return Zero if both are equals (even if both are nulls), a number less than zero if d1 is minor than d2 and a
 *         number greater than zero if d1 is greater than d2.
 * @see DateUtils#truncatedCompareTo(Calendar, Calendar, int)
 */
public static final int nullSafeCompareDateTime(Date d1, Date d2) {
    if (d1 == null || d2 == null) {
        if (d1 == d2) {
            return 0;
        }
        if (d1 == null) {
            return -1;
        }
        return 1;
    }
    return DateUtils.truncatedCompareTo(d1, d2, Calendar.SECOND);
}

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);
    cal.set(Calendar.MILLISECOND, 0);

    return cal.getTime();
}

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: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  v  a  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

/**
 * Adds a number of seconds to a date returning a new object.
 * The original date object is unchanged.
 *
 * @param date  the date, not null/*from   w  ww  .j  a va 2s .  c  o  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 addSeconds(Date date, int amount) {
    return add(date, Calendar.SECOND, amount);
}