List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:Main.java
public static void main(String[] args) { String text = "2011-10-02 18:48:05.123456"; Timestamp ts = Timestamp.valueOf(text); System.out.println(ts.getNanos()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Timestamp tstamp = new Timestamp(0); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root"); String sql = "INSERT myTable VALUES(?,?)"; PreparedStatement prest = con.prepareStatement(sql); prest.setString(1, "x"); prest.setTimestamp(2, tstamp.valueOf("2009-02-24 12:51:42.11")); int row = prest.executeUpdate(); System.out.println(row + " row(s) affected)"); }
From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java
public static void main(String args[]) throws ParseException { //Date date1 = new Date(playerDailyTaskModel.getCreateTime().getTime()); Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(new Date(Timestamp.valueOf("2012-04-15 20:00:00").getTime())); cal2.setTime(new Date(Timestamp.valueOf("2012-04-16 12:00:00").getTime())); System.out.println("cal1.WEEK_OF_YEAR=:" + cal1.get(Calendar.WEEK_OF_YEAR)); System.out.println("cal2.WEEK_OF_YEAR=:" + cal2.get(Calendar.WEEK_OF_YEAR)); }
From source file:Main.java
public static Date getRandomDate() { final long beginTime = Timestamp.valueOf("2017-01-13 00:00:00").getTime(); final long endTime = Timestamp.valueOf("2017-02-14 00:58:00").getTime(); long diff = endTime - beginTime + 1; long timeStamp = beginTime + (long) (Math.random() * diff); return new Date(timeStamp); }
From source file:Main.java
public static Timestamp dateTimeToTimeStamp(String dateInString) { if (dateInString != null) return Timestamp.valueOf(dateInString); else//from w ww. j av a 2 s . c o m return null; }
From source file:Main.java
public static long getTimestamp(String time) { time = time + ":00"; Timestamp ts = new Timestamp(System.currentTimeMillis()); try {/*from w w w . j a v a2s . co m*/ ts = Timestamp.valueOf(time); } catch (Exception e) { e.printStackTrace(); } return ts.getTime(); }
From source file:Main.java
/** * String->Timestamp/*from w w w . jav a 2 s . c o m*/ * * @param str * @return */ public static Timestamp strToTimestamp(String str) { return Timestamp.valueOf(str); }
From source file:Main.java
public static Timestamp parserTimestamp(String timestamp) { Timestamp ts = null;/*from w w w. j a v a2 s .c om*/ try { ts = Timestamp.valueOf(timestamp + " " + "00:00:00"); System.out.println(ts); } catch (Exception e) { e.printStackTrace(); } return ts; }
From source file:Main.java
/** * String->imestamp/*from w ww.j av a 2s .c om*/ * * @param str * @param format * @return */ public static Timestamp strToTimestamp(String str, String format) { // "yyyy-MM-dd HH:mm:ss" SimpleDateFormat df1 = new SimpleDateFormat(format); Date date1 = new Date(); try { date1 = df1.parse(str); } catch (ParseException e) { e.printStackTrace(); } String time = df1.format(date1); // Timestamp ts = Timestamp.valueOf(time); return Timestamp.valueOf(time); }
From source file:org.talend.dataquality.record.linkage.ui.composite.table.SortComparator.java
public static ISortComparator getSortComparator(int javaDataType) throws ParseException { switch (javaDataType) { case Types.DATE: case Types.TIME: return new SortComparator() { @Override/* w w w . j a v a2 s . c o m*/ public int compareNotNull(Object value1, Object value2) throws ParseException { return java.sql.Date.valueOf(value1.toString()) .compareTo(java.sql.Date.valueOf(value2.toString())); } }; case Types.TIMESTAMP: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Timestamp.valueOf(value1.toString()).compareTo(Timestamp.valueOf(value2.toString())); } }; case Types.DOUBLE: case Types.REAL: case Types.FLOAT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Double.valueOf(value1.toString()).compareTo(Double.valueOf(value2.toString())); } }; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.NUMERIC: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Integer.valueOf(value1.toString()).compareTo(Integer.valueOf(value2.toString())); } }; case Types.BIGINT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Long.valueOf(value1.toString()).compareTo(Long.valueOf(value2.toString())); } }; case Types.DECIMAL: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { if (value1 instanceof BigDecimal) { return ((BigDecimal) value1).compareTo((BigDecimal) value2); } BigDecimal b1 = new BigDecimal(value1.toString()); BigDecimal b2 = new BigDecimal(value2.toString()); return b1.compareTo(b2); } }; case Types.BOOLEAN: case Types.BIT: return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return Boolean.valueOf(value1.toString()).compareTo(Boolean.valueOf(value2.toString())); } }; default:// String return new SortComparator() { @Override public int compareNotNull(Object value1, Object value2) throws ParseException { return value1.toString().compareTo(value2.toString()); } }; } }