1. The Calendar to convert a String
// Get the current time, such as year, month, day,week,date, minute, and second
Calendar calendat = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(calendar.getTime());
Copy the code
2. The String into the Calendar
String str="2010-5-27";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date date =sdf.parse(str);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Copy the code
3. The Date String
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
String dateStr=sdf.format(new Date());
Copy the code
4. The String into the Date
String str="2010-5-27";
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
Date birthday = sdf.parse(str);
Copy the code
5. The Date into the Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(new java.util.Date());
Copy the code
6. The Calendar Date
Calendar calendar = Calendar.getInstance();
java.util.Date date =calendar.getTime();
Copy the code
Insert data from oracle table DATE as an example
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");
String date = sdf.format(new Date());
-----------------------------------------
String sql = "Insert into SM_SEND (*****************) " +
"values (******************************* "',1," + "to_date('" +date+ "', 'YYYY-MM-DD HH24:MI:SS')" + "," + "to_date('" +date+ "', 'YYYY-MM-DD HH24:MI:SS')" + ",0,null,null,null,null,null,null,null)";Copy the code