Example usage for java.sql Timestamp toLocaleString

List of usage examples for java.sql Timestamp toLocaleString

Introduction

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

Prototype

@Deprecated
public String toLocaleString() 

Source Link

Document

Creates a string representation of this Date object in an implementation-dependent form.

Usage

From source file:com.mothsoft.alexis.rest.dataset.v1.impl.DataSetResourceImpl.java

@Override
public Correlation correlate(Long dataSetAId, Long dataSetBId, Timestamp startDate, Timestamp endDate,
        String units) {// w w  w .j a va2s  . co  m
    if (units == null) {
        final Response response = Response.status(Status.BAD_REQUEST)
                .entity("Invalid Request: parameter 'units' expected").build();
        throw new WebApplicationException(response);
    }
    final TimeUnits unitEnum = TimeUnits.valueOf(units);

    com.mothsoft.alexis.domain.DataSet ds1 = null;
    com.mothsoft.alexis.domain.DataSet ds2 = null;

    try {
        ds1 = this.service.get(dataSetAId);
        ds2 = this.service.get(dataSetBId);
    } catch (final EntityNotFoundException nfe) {
        final Response response = Response.status(Status.BAD_REQUEST).entity("Invalid Request: unknown dataset")
                .build();
        throw new WebApplicationException(response);
    }

    if (startDate == null) {
        final Calendar calendar = new GregorianCalendar(1900, 0, 1);
        startDate = new Timestamp(calendar.getTime().getTime());
        logger.debug("Start Date: " + startDate.toLocaleString());
    }

    if (endDate == null) {
        endDate = new Timestamp(System.currentTimeMillis());
        logger.debug("End Date: " + endDate.toLocaleString());
    }

    return new Correlation(this.service.correlate(ds1, ds2, startDate, endDate, unitEnum));
}

From source file:com.p5solutions.core.jpa.orm.ConversionUtilityImpl.java

/**
 * Convert timestamp.//from  w ww. j av a  2s  .c  o  m
 * 
 * @param pb
 *          the pb
 * @param timestamp
 *          the timestamp
 * @param targetType
 *          the target type
 * @return the object
 */
public Object convertTimestamp(ParameterBinder pb, Timestamp timestamp, Class<?> targetType) {
    // TODO probably needs further checking based on JPA annotations, some
    // timezone issues???
    if (ReflectionUtility.isDate(targetType)) {
        // Check for Temporal
        if (pb != null) {
            Temporal temporal = pb.getTemporal();
            if (temporal != null) {
                Date converted = timestamp;
                if (TemporalType.DATE.equals(temporal.value())) {
                    java.sql.Date dt = new java.sql.Date(timestamp.getTime());
                    return dt;
                } else if (TemporalType.TIME.equals(temporal.value())) {
                    java.sql.Time tm = new java.sql.Time(timestamp.getTime());
                    return tm;
                } else if (TemporalType.TIMESTAMP.equals(temporal.value())) {

                }

                return converted;
            }
        }

        Date test = new Date(timestamp.getTime());
        return test;

        // return (Date) timestamp;
    } else if (ReflectionUtility.isStringClass(targetType)) {
        // TODO needs to be formatted based on the Format defined by the
        // 'custom?'
        // Format annotation ????
        return timestamp.toLocaleString();
    } else if (ReflectionUtility.isLongClass(targetType)) {

    }
    return timestamp;
}