Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

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

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:org.kuali.mobility.push.dao.DeviceDaoImplTest.java

@Test
@DirtiesContext//  w  w  w.ja va 2  s. c o  m
public void testSaveDeviceWithUpdate() {
    Device device = getDao().findDeviceByDeviceId("deviceIdA");
    assertTrue("Failed to find deviceIdA", device != null);
    Calendar cal = Calendar.getInstance();
    device.setPostedTimestamp(new Timestamp(cal.getTimeInMillis()));
    Long originalId = device.getId();
    getDao().saveDevice(device);
    assertTrue("Device id changed with update and should not have.", originalId.compareTo(device.getId()) == 0);
}

From source file:org.kuali.mobility.push.dao.DeviceDaoImplTest.java

@Test
@DirtiesContext/*w  w w  .  j  av a  2s  .co  m*/
public void testRegisterDeviceWithUpdate() {
    Device device = getDao().findDeviceByDeviceId("deviceIdA");
    assertTrue("Failed to find deviceIdA", device != null);
    Calendar cal = Calendar.getInstance();
    device.setPostedTimestamp(new Timestamp(cal.getTimeInMillis()));
    Long originalId = device.getId();
    getDao().saveDevice(device);
    assertTrue("Device id changed with update and should not have.", originalId.compareTo(device.getId()) == 0);
}

From source file:eu.optimis.mi.monitoring_manager.test.MonitoringManagerTest.java

protected void setUp() throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.set(2013, 0, 01, 01, 02, 03);//  w  w w.  j a  va2s .  c o m
    long ltimestamp = cal.getTimeInMillis() / 1000;
    String timestamp = Long.toString(ltimestamp);
    System.out.println(timestamp);
    physicalResource = "<?xml version='1.0'?><MonitoringResources><monitoring_resource>"
            + "<physical_resource_id>PhysicalUnitTestId</physical_resource_id>"
            + "<metric_name>cpu_average_load</metric_name><metric_value>0.030,0.050,0.010</metric_value>"
            + "<metric_unit></metric_unit><metric_timestamp>" + timestamp + "</metric_timestamp>"
            + "<service_resource_id></service_resource_id>" + "<virtual_resource_id></virtual_resource_id>"
            + "<resource_type>physical</resource_type>"
            + "<monitoring_information_collector_id></monitoring_information_collector_id>"
            + "</monitoring_resource><monitoring_resource>"
            + "<physical_resource_id>PhysicalUnitTestId</physical_resource_id>"
            + "<metric_name>disk_free_space</metric_name><metric_value>182929</metric_value>"
            + "<metric_unit></metric_unit><metric_timestamp>" + timestamp + "</metric_timestamp>"
            + "<service_resource_id></service_resource_id><virtual_resource_id></virtual_resource_id>"
            + "<resource_type>physical</resource_type>"
            + "<monitoring_information_collector_id></monitoring_information_collector_id>"
            + "</monitoring_resource></MonitoringResources>";

    virtualResource = "<?xml version='1.0'?><MonitoringResources><monitoring_resource>"
            + "<physical_resource_id>T</physical_resource_id>"
            + "<metric_name>mem_used</metric_name><metric_value>90</metric_value>"
            + "<metric_unit>percent</metric_unit><metric_timestamp>" + timestamp + "</metric_timestamp>"
            + "<service_resource_id></service_resource_id>"
            + "<virtual_resource_id>VirtualUnitTestId</virtual_resource_id>"
            + "<resource_type>virtual</resource_type>"
            + "<monitoring_information_collector_id></monitoring_information_collector_id>"
            + "</monitoring_resource><monitoring_resource>" + "<physical_resource_id>T</physical_resource_id>"
            + "<metric_name>cpu_user</metric_name><metric_value>0.04</metric_value>"
            + "<metric_unit>percent</metric_unit><metric_timestamp>" + timestamp + "</metric_timestamp>"
            + "<service_resource_id></service_resource_id><virtual_resource_id>VirtualUnitTestId</virtual_resource_id>"
            + "<resource_type>virtual</resource_type>"
            + "<monitoring_information_collector_id>test</monitoring_information_collector_id>"
            + "</monitoring_resource></MonitoringResources>";
    super.setUp();
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testDiffSameTime() {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = cal1;//w  w  w.  j  av  a 2s.c o  m
    assertEquals(0, DateHelper.diffInMillis(cal1.getTimeInMillis(), cal2.getTimeInMillis()));
}

From source file:com.hihframework.core.utils.DateUtils.java

/**
 * ? //from ww w  . ja v a  2 s  .c om
 *
 * @param date  
 * @return 
 */
public static java.sql.Date getDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    return new java.sql.Date(cal.getTimeInMillis());
}

From source file:no.met.jtimeseries.marinogram.MarinogramPlot.java

public List<Date> getShortTermTime(Date startTime) {
    if (startTime == null)
        return null;
    if (shortTermTime != null)
        return shortTermTime;
    shortTermTime = new ArrayList<Date>();
    shortTermTime.add(startTime);/*  w  ww  .j  a  v a 2  s . c  o m*/
    Calendar cal = Calendar.getInstance();
    cal.setTime(startTime);
    for (int i = 0; i < 48; i++) {
        cal.add(Calendar.HOUR_OF_DAY, 1);
        shortTermTime.add(new Date(cal.getTimeInMillis()));
    }
    return shortTermTime;
}

From source file:com.weavers.duqhan.business.impl.AdminServiceImpl.java

private String createToken(Long userId) {
    String token = null;/*from   w  w w.  j  a  v a2  s .c  o  m*/
    Calendar cal = Calendar.getInstance();
    if (userId != null) {
        token = RandomCodeGenerator.getNumericCode(4) + userId + cal.getTimeInMillis(); // generate new token
    }
    return token;
}

From source file:com.linkedin.drelephant.mapreduce.fetchers.MapReduceFSFetcherHadoop2Test.java

@Test
public void testGetHistoryDir() {
    FetcherConfiguration fetcherConf = new FetcherConfiguration(document9.getDocumentElement());
    try {//from www  .j av  a 2  s.c o m
        MapReduceFSFetcherHadoop2 fetcher = new MapReduceFSFetcherHadoop2(
                fetcherConf.getFetchersConfigurationData().get(0));
        Calendar timestamp = Calendar.getInstance();
        timestamp.set(2016, Calendar.JULY, 30);
        AnalyticJob job = new AnalyticJob().setAppId("application_1461566847127_84624")
                .setFinishTime(timestamp.getTimeInMillis());

        String expected = StringUtils.join(
                new String[] { fetcher.getHistoryLocation(), "2016", "07", "30", "000084", "" },
                File.separator);
        Assert.assertEquals("Error history directory", expected, fetcher.getHistoryDir(job));
    } catch (IOException e) {
        Assert.assertNull("Failed to initialize FileSystem", e);
    }
}

From source file:edu.depaul.armada.dao.ContainerDaoHibernate.java

@Override
public void deleteOldData(int interval) {
    Query query = sessionFactory.getCurrentSession()
            .createQuery("delete from Container c where c.timestamp <= :timestamp");

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, interval * -1);

    query.setTimestamp("timestamp", new Timestamp(cal.getTimeInMillis()));
    query.executeUpdate();/*from  w ww.ja  va  2 s.  c  o  m*/
}