Presentation is loading. Please wait.

Presentation is loading. Please wait.

Servlet Date Operations

Similar presentations


Presentation on theme: "Servlet Date Operations"— Presentation transcript:

1 Servlet Date Operations

2 Getting date from the user
Through HTML Form Since we are using bootstrap, date input must use bootstrap standard gui One of the plugins out there bootstrap-datetimepicker.min.js Jquery bootstrap date picker Can format the input MY format – mm-dd-yyyy

3 MYSQL DATE DATE DATETIME Conversion is needed
Yyyy-mm-dd DATETIME Yyyy-mm-dd hh:mm:ss – NOW | current time and date Conversion is needed From dd-mm-yyyy to yyyy-mm-dd

4 Java string to date conversion
String input from html form must be parsed into a java date object. //convert string to date String traveldate = request.getParameter("traveldate"); SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); try { date = formatter.parse(traveldate); } catch (Exception ex) { }

5 MY to mysql format conversion
//convert to mysql date formatter = new SimpleDateFormat("yyyy-MM-dd"); traveldate = formatter.format(date);

6 NOW() function for mysql
Exist in php for getting the current time and date Usually use to capture transaction date NOW() funtion not exist in Java Need to do manually

7 Current time and date in Java
//get current date and time Date currentdate = new Date(); //format directly to mysql date SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String bookingdate = formatter.format(currentdate);

8 MYSQL TO JAVA DATE CONVERSION
MYSQL DATE TO JAVA DATE //yyyy-MM-dd String traveldate = rs.getString("traveldate"); //convert traveldate string to date (still mysql date) SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); try { date = formatter.parse(traveldate); } catch (Exception ex) {}

9 //convert mysql date to MY date formatter = new SimpleDateFormat("dd-MM-yyyy"); traveldate = formatter.format(date);

10 MYSQL TO JAVA DATE CONVERSION
MYSQL DATETIME TO JAVA DATETIME //yyyy-MM-dd HH:mm:ss //parse the date from string for date conversion String bookingdate = rs.getString("bookingdate"); formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); date = new Date(); try { date = formatter.parse(bookingdate); } catch (Exception ex) {}

11 //convert to MY format dd-MM-yyyy formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a"); //formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss a"); //formatter = new SimpleDateFormat("dd MMMM, yyyy HH:mm:ss a"); bookingdate = formatter.format(date); a – AM/PM LET SAY MONTH IS NOVEMBER MM – 11 MMM – NOV MMMM – NOVEMBER


Download ppt "Servlet Date Operations"

Similar presentations


Ads by Google