I need to create two date objects. If the current date and time is March 9th 2012 11:30 AM then
- date object d1 should be 9th March 2012 12:00 AM
- date object d2 should contain the current date itself
The date will not be entered, it is system date.
Update:
Date dt = new Date(); System.out.print(dt.toString());
gives current date and time
Code To Get Today's date in any specific FormatgetTime(); String todaysdate = dateFormat. format(date); System. out. println("Today's date : " + todaysdate);
java. util. Date has no specific time zone, although its value is most commonly thought of in relation to UTC.
Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); System.out.println(sdf.format(date));
Calendar c = new GregorianCalendar(); c.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23 c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); Date d1 = c.getTime(); //the midnight, that's the first second of the day.
should be Fri Mar 09 00:00:00 IST 2012
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With