Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

In this page you can find the example usage for java.sql Date Date.

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date getDate(java.util.Date date) {
    if (date == null) {
        return currentDate();
    }/*from  www .  j ava  2  s.  co  m*/
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return new Date(c.getTimeInMillis());
}

From source file:nl.ordina.bag.etl.dao.postgres.BAGMutatiesDAOImpl.java

@Override
public long insertMutatiesFile(final java.util.Date dateFrom, final java.util.Date dateTo, final byte[] content)
        throws DAOException {
    try {/*from ww  w.j  av a 2 s  .  com*/
        return jdbcTemplate.query(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("insert into bag_mutaties_file (" + " id,"
                        + " date_from," + " date_to," + " content"
                        + ") values ((select coalesce(max(id),0) + 1 from bag_mutaties_file),date_trunc('day', ?::timestamp),date_trunc('day', ?::timestamp),?)"
                        + " returning id");
                ps.setDate(1, new Date(dateFrom.getTime()));
                ps.setDate(2, new Date(dateTo.getTime()));
                ps.setBytes(3, content);
                return ps;
            }
        }, new IdExtractor());
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:org.pgptool.gui.encryption.implpgp.KeyFilesOperationsPgpImpl.java

private static void fillDates(KeyInfo ret, PGPPublicKey key) {
    ret.setCreatedOn(new Date(key.getCreationTime().getTime()));
    if (key.getValidSeconds() != 0) {
        java.util.Date expiresAt = DateUtils.addSeconds(key.getCreationTime(), (int) key.getValidSeconds());
        ret.setExpiresAt(new Date(expiresAt.getTime()));
    }/*  ww w. ja  va 2  s  .  c  o m*/
}

From source file:com.impetus.kundera.property.accessor.SQLDateAccessor.java

@Override
public Date fromString(Class targetClass, String s) {

    if (s == null) {
        return null;
    }//from   ww w.ja  v a2s  .c  o  m
    if (StringUtils.isNumeric(s)) {
        return new Date(Long.parseLong(s));
    }
    Date d = Date.valueOf(s);
    return d;
}

From source file:su90.mybatisdemo.dao.EmployeesMapperTest.java

@Test(groups = { "find" })
public void testFindByRawProperties02() {
    try {//  w ww  .j a v a2 s .co m
        EmployeesMapper.EmployeeQuery sampleEQ = new EmployeesMapper.EmployeeQuery();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        java.util.Date startUtilDate = formatter.parse("20040101");
        java.util.Date endUtilDate = formatter.parse("20050101");
        sampleEQ.setStartHiredate(new Date(startUtilDate.getTime()));
        sampleEQ.setEndHiredate(new Date(endUtilDate.getTime()));
        List<Employee> result = employeesMapper.findByRawProperties(sampleEQ);
        assertEquals(result.size(), 10);
    } catch (ParseException ex) {
        assertTrue(false);
    }
}

From source file:puma.application.evaluation.AdvancedDocumentController.java

/**
* Creates an document with the given attributes. Retrus the identifier of the document
* @param params All attributes of the document. 'name', 'date' (in long format), 'tenant'
* @return Identifier of the created document
*//*w ww .  j av a  2 s .c  o  m*/
@ResponseBody
@RequestMapping(value = "/createDocument", method = RequestMethod.GET)
public String createDocument(@RequestParam MultiValueMap<String, String> params) {
    Document doc = new Document();
    if (params.containsKey("tenant"))
        doc.setCreatingTenant(params.getFirst("tenant"));
    if (params.containsKey("name"))
        doc.setName(params.getFirst("name"));
    if (params.containsKey("origin"))
        doc.setOrigin(params.getFirst("origin"));
    if (params.containsKey("destination"))
        doc.setDestination(params.getFirst("destination"));
    if (params.containsKey("date"))
        doc.setDate(new Date(Long.parseLong(params.getFirst("date"))));
    this.docService.addDocument(doc);
    return doc.getId().toString();
}

From source file:gov.nih.nci.integration.invoker.CaTissueSpecimenStrategyTest.java

/**
 * Tests createSpecimens using the ServiceInvocationStrategy class for the success scenario
 * /* w  w w. ja  v  a 2 s .  c  o  m*/
 * @throws IntegrationException - IntegrationException
 * @throws JAXBException - JAXBException
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void createSpecimens() throws IntegrationException, JAXBException {
    final Date stTime = new Date(new java.util.Date().getTime());

    xsltTransformer.transform(null, null, null);
    EasyMock.expectLastCall().andAnswer(new IAnswer() {

        public Object answer() {
            return getSpecimenXMLStr();
        }
    }).anyTimes();

    final ServiceInvocationResult clientResult = new ServiceInvocationResult();
    EasyMock.expect(caTissueSpecimenClient.createSpecimens((String) EasyMock.anyObject()))
            .andReturn(clientResult);
    EasyMock.replay(caTissueSpecimenClient);
    final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID,
            getSpecimenXMLStr(), stTime, caTissueSpecimenStrategy.getStrategyIdentifier());
    final ServiceInvocationResult strategyResult = caTissueSpecimenStrategy.invoke(serviceInvocationMessage);
    Assert.assertNotNull(strategyResult);
}

From source file:com.slownet5.pgprootexplorer.utils.FileUtils.java

public static String getLastModifiedDate(File file) {
    return new Date(file.lastModified()).toString();
}

From source file:org.beanfuse.security.service.UserServiceImpl.java

public void createUser(User creator, User newUser) {
    newUser.setCreator(creator);/*from  www .  ja  va 2  s. c  om*/
    newUser.setUpdatedAt(new Date(System.currentTimeMillis()));
    newUser.setCreatedAt(new Date(System.currentTimeMillis()));
    entityDao.saveOrUpdate(newUser);
}

From source file:com.qagen.osfe.core.utils.BeanPopulator.java

private static Date getDate(String name, String value, String format) {
    try {//from  w ww.j a  v a 2  s .  c  o  m
        if ((format == null) || (format.trim().length() == 0)) {
            final String message = "Column, " + name
                    + " is define as a Date and must the attribute, format, defined.";
            throw new FeedErrorException(message);
        }

        final SimpleDateFormat formatter = new SimpleDateFormat(format);
        return new Date(formatter.parse(value).getTime());

    } catch (ParseException e) {
        throw new FeedErrorException(e);
    }
}