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.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);/*  ww  w .  j  ava  2  s .  c  o  m*/

    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:com.amazon.alexa.avs.auth.OAuth2AccessToken.java

/**
 * Creates an {@link OAuth2AccessToken} object.
 *
 * @param accessToken The accessToken returned from LWA.
 * @param expiresIn Time in seconds that the accessToken expires in.
 *///w  ww . j a v a 2 s  .c o m
public OAuth2AccessToken(String accessToken, int expiresIn) {
    if (StringUtils.isBlank(accessToken)) {
        throw new IllegalArgumentException("Missing " + AuthConstants.OAuth2.ACCESS_TOKEN + " parameter");
    }

    if (expiresIn < 0) {
        throw new IllegalArgumentException(
                "Invalid " + AuthConstants.OAuth2.EXPIRES_IN + " value. Must be a positive number.");
    }

    Date currentDate = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);
    calendar.add(Calendar.SECOND, expiresIn);

    this.accessToken = accessToken;
    this.expiresTime = calendar.getTime().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;/*w  w  w .jav  a  2  s. c o  m*/
}

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);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);//from  w ww . j av  a 2s  .co m
    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.autentia.common.util.DateFormater.java

public static Date normalizeInitDate(Date date) {

    GregorianCalendar gCalendar = new GregorianCalendar();
    gCalendar.setTime(date);//  w ww. j a  v  a  2s .c  o  m
    gCalendar.set(Calendar.HOUR_OF_DAY, 0);
    gCalendar.set(Calendar.MINUTE, 0);
    gCalendar.set(Calendar.SECOND, 0);
    gCalendar.set(Calendar.MILLISECOND, 0);

    return gCalendar.getTime();
}

From source file:com.ar.dev.tierra.api.dao.impl.TransferenciaDAOImpl.java

@Override
public List<Transferencia> getDaily() {
    Criteria criteria = getSession().createCriteria(Transferencia.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.desc("idTransferencia"));
    List<Transferencia> list = criteria.list();
    return list;/*from   www .j  a va 2  s  . c  o  m*/
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date addTime(Date date, Date time) {
    Calendar timeCal = setTime(time);

    int hour = timeCal.get(Calendar.HOUR_OF_DAY);
    int mins = timeCal.get(Calendar.MINUTE);
    int secs = timeCal.get(Calendar.SECOND);

    Calendar cal = setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, mins);
    cal.set(Calendar.SECOND, secs);

    return cal.getTime();
}

From source file:at.christophwurst.orm.service.BurnDownServiceImpl.java

private Date stripDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w  w  w  .  j a  v  a  2  s  . c o  m
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:ezbake.data.elastic.test.models.PlaceOfInterest.java

public void setVisit(Date visit) {
    this.visit = DateUtils.truncate(visit, Calendar.SECOND);
}

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

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();//from  ww w  .java 2s  .c om
    grain = new DayConsolidator(client);

    List<Map<String, Object>> stats = (new HourConsolidator(client)).consolidateData();
    Map<String, Object> timeMap = new HashMap<String, Object>();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 1);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            cal.add(Calendar.DATE, -1);
        }
        timeMap.put(CONSOLIDATION_MAX, cal.getTime());
        timeMap.put(CONSOLIDATION_MIN, cal.getTime());
        for (Map<String, Object> data : stats) {
            data.put(STAT_TIMESTAMP, timeMap);
        }
        client.storeData(stats);
    }
    dataCount = coll.count();
}