|
By Prasanna Sherekar |
Convert Java 8 LocalDateTime to Util Date Object Example
|
LocalDateTime localDateTime = LocalDateTime.now(); Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); System.out.println("date===> " + date); |
Output:
date===> Wed Feb 10 17:48:18 IST 2016
|
By Prasanna Sherekar |
Calculate Difference Between Two Dates – Java Example
Take a look @ Joda-Time FAQ
You can use a PeriodFormatter to get the format of your choice.
Try the following sample code.
|
DateTime dt = new DateTime(); DateTime twoHoursLater = dt.plusHours(2).plusMinutes(10).plusSeconds(5); Period period = new Period(dt, twoHoursLater); PeriodFormatter HHMMSSFormater = new PeriodFormatterBuilder() .printZeroAlways() .minimumPrintedDigits(2) .appendHours().appendSeparator("-") .appendMinutes().appendSeparator("-") .appendSeconds(); .toFormatter(); // produce thread-safe formatter System.out.println(HHMMSSFormater.print(period)); |
|
By Prasanna Sherekar |
Format Date in JSP using JSTL – Java Example
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <html> <head> </head> <body> <jsp:useBean id="date" class="java.util.Date"/> Today is: <fmt:formatDate value="${date}" type="date" pattern="dd-MMM-yyyy"/> </body> </html> |