To get a date object set to a specific date you can use the Calendar class as follows in the following example code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// // The following example code demonstrates how to // create a Date object set to a specific date and time using the Calendar class. // public class GetSpecificDateObject { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.SECOND, 8); calendar.set(Calendar.MINUTE, 8); calendar.set(Calendar.HOUR, 8); calendar.set(Calendar.AM_PM, Calendar.AM); calendar.set(Calendar.MONTH, Calendar.AUGUST); calendar.set(Calendar.DAY_OF_MONTH, 8); calendar.set(Calendar.YEAR, 2008); Date date = calendar.getTime(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a"); System.out.println(dateFormat.format(date)); } } |
Here is the output of the example code:
1 |
2008-08-08 08:08:08 AM |
Subscribe To Our Newsletter
Join our low volume mailing list to receive the latest news and updates from our team.