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:com.digitalpebble.stormcrawler.persistence.DefaultSchedulerTest.java

@Test
public void testScheduler() throws MalformedURLException {
    Map<String, Object> stormConf = new HashMap<>();
    stormConf.put("fetchInterval.testKey=someValue", 3600);
    DefaultScheduler scheduler = new DefaultScheduler();
    scheduler.init(stormConf);//from w  ww  .j  av  a2 s. c om

    Metadata metadata = new Metadata();
    metadata.addValue("testKey", "someValue");
    Date nextFetch = scheduler.schedule(Status.FETCHED, metadata);

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, 3600);
    Assert.assertEquals(DateUtils.round(cal.getTime(), Calendar.SECOND),
            DateUtils.round(nextFetch, Calendar.SECOND));
}

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

 public static Calendar getCalendar(int yyyy, int mm, int dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, yyyy);/*from  www  .  j a  v  a2s .  c  om*/
   cal.set(Calendar.MONTH, mm - 1);
   cal.set(Calendar.DATE, dd);
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:Main.java

public static Date getDateTimeFrom(Date iDate, int mode, int adddate) {

    Calendar calendar = Calendar.getInstance();
    Calendar calendarDate = Calendar.getInstance();
    calendarDate.setTime(iDate);/*w  ww.j a  va  2s  .  c o  m*/

    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    switch (mode) {

    case Calendar.DAY_OF_MONTH: {
        calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH) + adddate);
    }
        break;

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

    return ret;
}

From source file:com.watchrabbit.crawler.manager.policy.BasicRevisitPolicy.java

private Date getNextMinimumDate() {
    Calendar now = clock.getCalendar();
    now.add(Calendar.SECOND, minimumIntervalBetweenCrawls);
    return now.getTime();
}

From source file:Main.java

/**
 * <p>Checks if two calendar objects represent the same local time.</p>
 *
 * <p>This method compares the values of the fields of the two objects.
 * In addition, both calendars must be the same of the same type.</p>
 * /* w w w.j  ava 2  s .c o  m*/
 * @param cal1  the first calendar, not altered, not null
 * @param cal2  the second calendar, not altered, not null
 * @return true if they represent the same millisecond instant
 * @throws IllegalArgumentException if either date is <code>null</code>
 * @since 2.1
 */
public static boolean isSameLocalTime(Calendar cal1, Calendar cal2) {
    if (cal1 == null || cal2 == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    return (cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND)
            && cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND)
            && cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE)
            && cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
            && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.getClass() == cal2.getClass());
}

From source file:com.linuxbox.enkive.teststats.StatsHourGrainTest.java

@SuppressWarnings("unchecked")
@BeforeClass//from   www  . j ava2s. c  o m
public static void setUp() throws ParseException, GathererException {
    gatherTester = TestHelper.BuildGathererService();
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();
    grain = new HourConsolidator(client);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    for (int i = 0; i < 10; i++) {
        List<RawStats> stats = gatherTester.gatherStats();
        List<Map<String, Object>> statsToStore = createListOfMaps();
        if (i == 5) {
            cal.add(Calendar.HOUR, -1);
        }

        for (RawStats data : stats) {
            Map<String, Object> temp = data.toMap();
            Map<String, Object> date = (Map<String, Object>) temp.get(STAT_TIMESTAMP);
            date.put(CONSOLIDATION_MIN, cal.getTime());
            date.put(CONSOLIDATION_MAX, cal.getTime());
            date.put(STAT_TS_POINT, cal.getTime());
            statsToStore.add(temp);
        }
        client.storeData(statsToStore);
    }
    dataCount = coll.count();
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * /*  ww  w  .  ja  v a  2s  .c o  m*/
 *
 * @param date
 * @param secondAmount
 * @return Date
 */
public static Date addSecond(Date date, int secondAmount) {
    return addInteger(date, Calendar.SECOND, secondAmount);
}

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

public static long getTimeinMillis4FullDateTimeGMT(int year, int month, int day, int hours, int minutes,
        int seconds) {
    Calendar c = getCalendarGMT();

    c.set(Calendar.YEAR, year);//from ww w.  j a  va  2s  .  co m
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);

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

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

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

    return timeinmillis;
}

From source file:com.lfv.yada.net.server.ServerLogger.java

public ServerLogger(int groupId, String logpath) {
    // Create a logger for this class
    if (logpath == null) {
        logpath = "data/logs/";
    }//from  w  w w.ja  v  a 2 s.  c o  m
    mylogpath = logpath;
    log = LogFactory.getLog(getClass());
    log.info("ServerLogger: logpath=" + logpath);

    // Create a calendar
    startTime = System.currentTimeMillis();
    calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTimeInMillis(startTime);
    String filename = "Grp" + groupId + "-" + calendar.get(Calendar.YEAR) + s2(calendar.get(Calendar.MONTH) + 1)
            + s2(calendar.get(Calendar.DAY_OF_MONTH)) + "-" + s2(calendar.get(Calendar.HOUR_OF_DAY))
            + s2(calendar.get(Calendar.MINUTE)) + s2(calendar.get(Calendar.SECOND)) + ".log";
    try {
        printer = new PrintStream(new FileOutputStream(logpath + "/" + filename), true);

        log.info("Creating log " + logpath + "/" + filename);
    } catch (FileNotFoundException ex) {
        log.warn("Log file " + filename + " could not be created, logger has been disabled!", ex);
        printer = null;
    }
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);/* ww  w. j a v a 2  s.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)));
}