Java by API/java.sql/Timestamp
Содержание
new Timestamp(long time)
public class Main {
public static void main(String[] args) {
java.util.Date today = new java.util.Date();
java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime());
java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2005-04-06 09:01:10");
long tsTime1 = ts1.getTime();
long tsTime2 = ts2.getTime();
System.out.println(tsTime1);
System.out.println(tsTime2);
}
}
Timestamp: getTime()
public class Main {
public static void main(String[] args) {
java.util.Date today = new java.util.Date();
java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime());
java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2005-04-06 09:01:10");
long tsTime1 = ts1.getTime();
long tsTime2 = ts2.getTime();
System.out.println(tsTime1);
System.out.println(tsTime2);
}
}
Timestamp: toString()
public class Main {
public static void main(String[] args) {
java.util.Date javaDate = new java.util.Date();
long javaTime = javaDate.getTime();
System.out.println("The Java Date is: " + javaDate.toString());
java.sql.Date sqlDate = new java.sql.Date(javaTime);
System.out.println("The SQL DATE is: " + sqlDate.toString());
java.sql.Time sqlTime = new java.sql.Time(javaTime);
System.out.println("The SQL TIME is: " + sqlTime.toString());
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime);
System.out.println("The SQL TIMESTAMP is: " + sqlTimestamp.toString());
}
}
Timestamp: valueOf(String s)
public class Main {
public static void main(String[] args) {
java.util.Date today = new java.util.Date();
java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime());
java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2005-04-06 09:01:10");
long tsTime1 = ts1.getTime();
long tsTime2 = ts2.getTime();
System.out.println(tsTime1);
System.out.println(tsTime2);
}
}