Example usage for java.sql Timestamp valueOf

List of usage examples for java.sql Timestamp valueOf

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) 

Source Link

Document

Obtains an instance of Timestamp from a LocalDateTime object, with the same year, month, day of month, hours, minutes, seconds and nanos date-time value as the provided LocalDateTime .

Usage

From source file:jp.zippyzip.City.java

/**
 * JSON ???//from  w  w  w.jav a  2  s .  com
 * 
 * @param json JSON
 * @return 
 */
public static City fromJson(String json) {

    City ret = null;

    try {

        JSONObject jo = new JSONObject(json);

        ret = new City(jo.optString("code", ""), jo.optString("name", ""), jo.optString("yomi", ""),
                Timestamp.valueOf(jo.optString("expiration", "")));

    } catch (JSONException e) {
        log.log(Level.WARNING, "", e);
    }

    return ret;
}

From source file:org.apache.hive.storage.jdbc.spitter.TimestampIntervalSplitter.java

@Override
public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions,
        TypeInfo typeInfo) {/*from   w w  w .  ja v a2s  .  c  o  m*/
    List<MutablePair<String, String>> intervals = new ArrayList<>();
    Timestamp timestampLower = Timestamp.valueOf(lowerBound);
    Timestamp timestampUpper = Timestamp.valueOf(upperBound);
    // Note nano is not fully represented as the precision limit
    double timestampInterval = (timestampUpper.getTime() - timestampLower.getTime()) / (double) numPartitions;
    Timestamp splitTimestampLower, splitTimestampUpper;
    for (int i = 0; i < numPartitions; i++) {
        splitTimestampLower = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval * i));
        splitTimestampUpper = new Timestamp(Math.round(timestampLower.getTime() + timestampInterval * (i + 1)));
        if (splitTimestampLower.compareTo(splitTimestampUpper) < 0) {
            intervals.add(new MutablePair<String, String>(splitTimestampLower.toString(),
                    splitTimestampUpper.toString()));
        }
    }
    return intervals;
}

From source file:com.sgu.findyourfriend.utils.MessageParser.java

public static Message getMsg(JSONObject jS) {

    Message s = null;//ww  w.  ja v a2 s .  co m

    try {
        String msg = jS.getString("msg");
        int idSender = jS.getInt("sender");
        int idReceiver = jS.getInt("recipient");
        Timestamp smsTime = Timestamp.valueOf(jS.getString("timest"));

        //         String senderName = FriendManager.getInstance().getNameFriend(idSender);
        //         String receiverName = FriendManager.getInstance().getNameFriend(idReceiver);

        //         new Message(message, MyProfileManager.getInstance().getMyID() == idSender,
        //               idSender, senderName, idReceiver, receiverName, location, smsTime)

        s = Utility.parseMessage(msg);
        s.setSmsTime(smsTime);
        // s = new Message(msg, false, idSender, idReceiver, smsTime);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return s;
}

From source file:net.jmhertlein.mcanalytics.plugin.daemon.request.UniqueLoginsPerDayRequestHandler.java

@Override
public JSONObject handle(Connection conn, StatementProvider stmts, JSONObject request, ClientMonitor client)
        throws Exception {
    PreparedStatement stmt = conn.prepareStatement(stmts.get(SQLString.GET_UNIQUE_LOGINS));

    stmt.clearParameters();/*from w w w  . j  av  a 2  s. c  o m*/
    stmt.setTimestamp(1, Timestamp.valueOf(LocalDate.parse(request.getString("start")).atStartOfDay()));
    stmt.setTimestamp(2,
            Timestamp.valueOf(LocalDate.parse(request.getString("end")).plusDays(1).atStartOfDay()));
    ResultSet res = stmt.executeQuery();

    Map<String, Integer> counts = new HashMap<>();
    while (res.next()) {
        counts.put(res.getTimestamp("login_day").toLocalDateTime().toLocalDate().toString(),
                res.getInt("login_count"));
    }

    JSONObject ret = new JSONObject();
    ret.put("logins", counts);
    res.close();
    stmt.close();
    return ret;
}

From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.utility.CreateBinaryDatafile.java

public String generateDatetime() {
    long offset = Timestamp.valueOf("2015-02-21 00:00:00").getTime();
    long end = Timestamp.valueOf("2015-02-24 00:00:00").getTime();
    long diff = end - offset + 1;
    Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss.SSS");

    return sdf.format(rand);
}

From source file:com.zhengxuetao.springmvc.DayDataTest.java

@Test
public void testFindDayData() {
    DayService dayService = context.getBean("dayService", DayService.class);
    List<DayData> list = dayService.findDayDataList(600009l, Timestamp.valueOf("2017-05-01 00:00:00"),
            Timestamp.valueOf("2017-05-25 00:00:00"));
    LoggerFactory.logger(DayDataTest.class).info("DayData size:" + list.size());
}

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

public static Object getValueAsType(String name, String value, String type, String format) {
    if ((value != null) && (value.trim().length() == 0)) {
        return null;
    }/*from  w  ww  .  j  a  v  a  2 s  .  c  o  m*/

    if (type.equals(AttributeType.String.name())) {
        return value;
    }

    if (type.equals(AttributeType.Integer.name())) {
        return Integer.parseInt(value);
    }

    if (type.equals(AttributeType.Float.name())) {
        return Float.parseFloat(value);
    }

    if (type.equals(AttributeType.Double.name())) {
        return Double.parseDouble(value);
    }

    if (type.equals(AttributeType.Boolean.name())) {
        return Boolean.parseBoolean(value);
    }

    if (type.equals(AttributeType.Date.name())) {
        return getDate(name, value, format);
    }

    if (type.equals(AttributeType.Time.name())) {
        return getTime(name, value, format);
    }

    if (type.equals(AttributeType.Long.name())) {
        return Long.parseLong(value);
    }

    if (type.equals(AttributeType.Timestamp.name())) {
        return getTimestamp(name, value, format);
    }

    if (type.equals(AttributeType.Object.name())) {
        return Timestamp.valueOf(value);
    }

    final String message = "The value type, " + type + " is not a defined type.  "
            + "You may need to extend the RowParser class and override the method, getValueAsType().";
    throw new FeedErrorException(message);
}

From source file:vn.edu.vttu.ui.PanelStatiticsRevenue.java

private void statiticsDay() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String datetimeStart = formatter.format(dtFormDate.getDate());
    Timestamp tsStart = Timestamp.valueOf(datetimeStart);
    String datetimeEnd = formatter.format(dtToDate.getDate());
    Timestamp tsToDate = Timestamp.valueOf(datetimeEnd);
    tbResult.setModel(Invoice.getStatiticsByDate(tsStart, tsToDate, ConnectDB.conn()));
}

From source file:com.helixleisure.candidates.test.ThriftSerializeDeserializeTest.java

/**
 * Shows how to serialize one object to binary format.
 * @throws Exception/*from www  . j  av  a 2  s .com*/
 */
@Test
public void testSerialize() throws Exception {
    Data locationProperty = DataHelper.makeLocationProperty(Timestamp.valueOf("2015-05-01 10:00:00"), 12345L,
            "Acme Inc.");
    assertEquals(
            "Data(pedigree:Pedigree(timestamp:2015-05-01 10:00:00.0), dataunit:<DataUnit location_property:LocationProperty(id:<LocationID location_id:12345>, property:<LocationPropertyValue location_name:Acme Inc.>)>)",
            locationProperty.toString());
    String expectedHex = "0c00010b000100000015323031352d30352d30312031303a30303a30302e30000c00020c00010c00010a00010000000000003039000c00020b00010000000941636d6520496e632e00000000";
    byte[] serialize = ser.serialize(locationProperty);
    assertEquals(expectedHex, Hex.encodeHexString(serialize));
}

From source file:org.apache.stratos.usage.summary.helper.HourlySummarizerHelper.java

public void execute() {
    log.info("Running custom analyzer for Stratos usage hourly summarization.");
    try {//from   ww w  . j a v a2 s . com
        String lastHourlyTimestampStr = DataAccessObject.getInstance().getAndUpdateLastUsageHourlyTimestamp();
        Long lastHourlyTimestamp = Timestamp.valueOf(lastHourlyTimestampStr).getTime();

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
        String currentTsStr = formatter.format(new Date().getTime());

        log.info("Running hourly usage analytics from " + lastHourlyTimestampStr + " to " + currentTsStr);
        setProperty("last_hourly_ts", lastHourlyTimestamp.toString());
    } catch (Exception e) {
        log.error("An error occurred while setting hour range for hourly usage analysis. ", e);
    }
}