// Fetch current date :
Calender calender = Calender.getInstance();
Date currentDate = calender.getTime();
// Printing current date in terminal :
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss");
System.setProperty("current_time", dateFormat.format(new Date()));
// Converting String to Date to String to Date
String endDate = "20200728";
Date date1 = new SimpleDateFormat("yyyyMMdd").parse(endDate);
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
String str = newFormat.format(date1);
Date date2 = newFormat(str);
Java String to Date Example :
String sDate1="10/03/1994";
Date date1=new SimpleDateFormat("dd/MM/yyyy").parse(sDate1);
System.out.println(sDate1+"\t"+date1);
Java Date to String Example :
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = dateFormat.format(date);
System.out.println("Before conversion of date into String: " + date);
System.out.println("After conversion of date into String: " + strDate);
// Inserting user data into EMP table
Connection connection = Platform.getConnection();
PreparedStatement pstmt = connection.prepareStatement("insert into EMP(userLogin,employeeNumber,reason,end_Date) values(?,?,?,?)");
pstmt.setString(1, userLogin);
pstmt.setString(2, upi);
pstmt.setString(3, reason);
pstmt.setDate(4, new java.sql.Date(date2.getTime));
pstmt.exceuteUpdate();
connection.commit();
No comments:
Post a Comment