I run into the struggle of converting one data type to another all the time. And obviously, I don't recollect instantly how to convert one from another. So here's some notes for me & hopefully they will useful for you as well.
CaptiveCode
// 1. Get Date from Calendar int year=2016; int month=1; int date=1; Calendar cal = Calendar.getInstance(); cal.set(year, month, date); java.util.Date utilDate = cal.getTime(); // 2. Convert java.util.Date to java.sql.Date java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); // 3. Convert java.sql.Date to oracle.jbo.domain.Date java.sql.Date sqlDate = new java.sql.Date(); new jbo.domain.Date(sqlDate); /* To get current date & time in jbo.domain.Date */ java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate); // 4. Convert java.util.Date to java.sql.Timestamp java.util.Date utilDate = new java.util.Date(); java.sql.Timestamp timestamp_now = new java.sql.Timestamp(utilDate.getTime())
Please share your feedback below. Hope you find this helpful!
CaptiveCode
No comments:
Post a Comment