Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:org.kuali.mobility.feedback.controllers.FeedbackController.java

@RequestMapping(method = RequestMethod.POST)
public String submitFeedback(Model uiModel, @ModelAttribute("feedback") Feedback feedback,
        BindingResult result) {//w w w.j av  a2 s . c  o m
    feedback.setPostedTimestamp(new Timestamp(System.currentTimeMillis()));
    //        feedback.setAffiliation(page.getUser().getAffiliation());   
    //        feedback.setCampus(page.getUser().getCampus());
    //        if (params.get("uid") != null) {
    //            feedback.setUserId(params.get("uid"));
    //        } else {
    //            if (page.getUser().isCasAuthenticated()) {
    //               feedback.setUserId(page.getUser().getPerson().getUserId());
    //            }
    //        }
    if (isValidFeedback(feedback, result)) {
        feedbackService.saveFeedback(feedback);
        return "feedback/thanks";
    } else {
        uiModel.addAttribute("deviceTypes", deviceTypes);
        return "feedback/form";
    }
}

From source file:com.google.enterprise.connector.db.diffing.DBHandleTest.java

protected void setUp() throws Exception {
    long lastModifiedMillis = new Date().getTime();
    Calendar lastModifiedCalendar = Calendar.getInstance();
    lastModifiedCalendar.setTimeInMillis(lastModifiedMillis);
    lastModified = Value.calendarToIso8601(lastModifiedCalendar);

    properties = ImmutableMap.of(SpiConstants.PROPNAME_DOCID, "1", SpiConstants.PROPNAME_ISPUBLIC, "false",
            SpiConstants.PROPNAME_MIMETYPE, "text/plain", SpiConstants.PROPNAME_LASTMODIFIED, lastModified);

    JsonObjectUtil jsonObjectUtil = new JsonObjectUtil();
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        jsonObjectUtil.setProperty(entry.getKey(), entry.getValue());
    }//from  w  w  w  . j  a va2  s .  c  o m
    // Overwrites the string in jsonObjectUtil with a date value.
    jsonObjectUtil.setLastModifiedDate(SpiConstants.PROPNAME_LASTMODIFIED, new Timestamp(lastModifiedMillis));
    jsonDocument = new JsonDocument(jsonObjectUtil.getProperties(), jsonObjectUtil.getJsonObject());
}

From source file:org.uaa.security.SecurityService.java

public void updateLastLoginInfo(String username, String addr) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("username", username);
    params.put("last_login_addr", addr);
    params.put("last_login_time", new Timestamp(System.currentTimeMillis()));
    securityMapper.updateLastLoginInfo(params);
}

From source file:com.vrv.common.converter.DateConverter.java

@SuppressWarnings("rawtypes")
protected Object convertToDate(Class type, Object value, String pattern) {
    DateFormat df = new SimpleDateFormat(pattern);
    if (value instanceof String) {
        try {/*  w  ww  . jav a2 s.  c  o m*/
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }
            Date date = df.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Timestamp) {
        try {
            Timestamp timestamp = (Timestamp) value;
            Date date = new Date(timestamp.getTime());
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting Timestamp to Date");
        }
    } else if (value instanceof java.sql.Date) {
        try {
            java.sql.Date sqlDate = (java.sql.Date) value;
            return new Date(sqlDate.getTime());
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Date) {
        return value;
    }
    throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
}

From source file:com.fluke.application.IEODReader.java

static Timestamp getTimestamp(String date, String time) {
    String year = date.substring(0, 4);
    String month = date.substring(4, 6);
    String day = date.substring(6, 8);
    String timeParts[] = time.split(":");

    Date givenDate = Util.getIEODDate(day + "-" + month + "-" + year + "," + timeParts[0] + ":" + timeParts[1]);
    return new Timestamp(givenDate.getTime());
}

From source file:org.bpmscript.process.hibernate.HibernateInstanceManager.java

/**
 * @see org.bpmscript.process.IInstanceManager#createInstance(java.lang.String,
 *      java.lang.String, java.lang.String)
 *///from w  w  w  . ja v  a2  s  .c  om
public String createInstance(String parentVersion, String definitionId, String definitionName,
        String definitionType, String operation) throws BpmScriptException {
    HibernateInstance instance = new HibernateInstance();
    instance.setCreationDate(new Timestamp(System.currentTimeMillis()));
    instance.setDefinitionId(definitionId);
    instance.setOperation(operation);
    instance.setDefinitionName(definitionName);
    instance.setDefinitionType(definitionType);
    instance.setParentVersion(parentVersion);
    getHibernateTemplate().save(instance);
    return instance.getId();
}

From source file:com.github.nmorel.gwtjackson.shared.options.DateOptionsTester.java

public void testSerializeDatesAsTimestamps(ObjectWriterTester<BeanWithDates> writer) {
    BeanWithDates bean = new BeanWithDates();
    bean.date = new Date(1345304756540l);
    bean.onlyDate = new Date(1345304756540l);
    bean.onlyDateTz = new Date(1345304756540l);
    bean.sqlDate = new java.sql.Date(1345304756541l);
    bean.sqlTime = new Time(1345304756542l);
    bean.sqlTimestamp = new Timestamp(1345304756543l);

    Map<Date, String> mapDate = new HashMap<Date, String>();
    mapDate.put(new Date(1345304756544l), "java.util.Date");
    bean.mapDate = mapDate;// ww  w .j a va 2s.  c  om

    Map<java.sql.Date, String> mapSqlDate = new HashMap<java.sql.Date, String>();
    mapSqlDate.put(new java.sql.Date(1345304756545l), "java.sql.Date");
    bean.mapSqlDate = mapSqlDate;

    Map<Time, String> mapSqlTime = new HashMap<Time, String>();
    mapSqlTime.put(new Time(1345304756546l), "java.sql.Time");
    bean.mapSqlTime = mapSqlTime;

    Map<Timestamp, String> mapSqlTimestamp = new HashMap<Timestamp, String>();
    mapSqlTimestamp.put(new Timestamp(1345304756547l), "java.sql.Timestamp");
    bean.mapSqlTimestamp = mapSqlTimestamp;

    String expected = "{" + "\"date\":1345304756540," + "\"onlyDate\":\"/2012/08/18/\","
            + "\"onlyDateTz\":\"/2012/08/18/ +0000\"," + "\"sqlDate\":\"" + bean.sqlDate.toString() + "\","
            + "\"sqlTime\":\"" + bean.sqlTime.toString() + "\"," + "\"sqlTimestamp\":1345304756543,"
            + "\"mapDate\":{\"1345304756544\":\"java.util.Date\"},"
            + "\"mapSqlDate\":{\"1345304756545\":\"java.sql.Date\"},"
            + "\"mapSqlTime\":{\"1345304756546\":\"java.sql.Time\"},"
            + "\"mapSqlTimestamp\":{\"1345304756547\":\"java.sql.Timestamp\"}" + "}";

    assertEquals(expected, writer.write(bean));
}

From source file:cn.mypandora.controller.MyUpload.java

/**
 * @param part//from   ww  w .  ja v a 2  s .c  o m
 * @return void
 * @Title: upload
 * @Description: 
 */
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(@RequestParam("myFile") Part part, @RequestParam("choosePath") String choosePath) {
    try {
        /* ? */
        /* ? */
        ResourceBundle resourceBundle = ResourceBundle.getBundle("upload");
        String savePath = resourceBundle.getString(choosePath != null ? choosePath : "defaultPath")
                + getFileName(part);
        // String webRootPath = request.getServletContext().getRealPath("/upload");
        String webRootPath = System.getProperty("contentPath");
        part.write(webRootPath + savePath);

        // ??
        UploadFile file = new UploadFile();
        file.setFileSize(part.getSize());
        file.setFileName(getFileName(part));
        file.setSaveName(getFileName(part));
        file.setFileType(1);
        file.setSavePath(savePath);
        file.setCreateTime(new Timestamp(1234567890L));
        file.setUpdateTime(new Timestamp(1234567891L));
        baseUploadService.saveFile(file);

        //            return file;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java

public void saveOrUpdateEmail(final Email email) {
    if (email.getDateCreate() == null) {
        email.setDateCreate(new Timestamp(new Date().getTime()));
    }/*from  w w w  .  ja va 2 s  . c  o  m*/
    if (StringUtils.isEmpty(email.getStatus())) {
        email.setStatus(Email.EMAIl_STATUS_PENDING);
    }
    email.setDateUpdate(new Timestamp(new Date().getTime()));

    if (email.getId() == null) {
        em.persist(email);
    } else {
        em.merge(email);
    }
}