I want to remove time from Date
object.
DateFormat df; String date; df = new SimpleDateFormat("dd/MM/yyyy"); d = eventList.get(0).getStartDate(); // I'm getting the date using this method date = df.format(d); // Converting date in "dd/MM/yyyy" format
But when I'm converting this date (which is in String
format) it is appending time also.
I don't want time at all. What I want is simply "21/03/2012".
Use the toDateString() method to remove the time from a date, e.g. new Date(date. toDateString()) . The method returns only the date portion of a Date object, so passing the result to the Date() constructor would remove the time from the date. Copied!
To remove the T and Z characters from an ISO date in JavaScript, we first need to have the date in ISO format. If you don't have it already, you can convert it to ISO using the toISOString function on a Date object. This will get rid of both T and Z, resulting in "2022-06-22 07:54:52.657".
You can remove the time part from java.util.Date by setting the hour, minute, second and millisecond values to zero.
import java.util.Calendar; import java.util.Date; public class DateUtil { public static Date removeTime(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); } }
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