Removing time from a Date object?

前端 未结 19 1292
余生分开走
余生分开走 2020-12-15 02:26

I want to remove time from Date object.

DateFormat df;
String date;
df = new SimpleDateFormat(\"dd/MM/yyyy\");
d = eventList.get(0).getStartDate         


        
19条回答
  •  无人及你
    2020-12-15 02:47

    May be the below code may help people who are looking for zeroHour of the day :

        Date todayDate = new Date();
        GregorianCalendar todayDate_G = new GregorianCalendar();
        gcd.setTime(currentDate);
        int _Day    = todayDate_GC.get(GregorianCalendar.DAY_OF_MONTH);
        int _Month  = todayDate_GC.get(GregorianCalendar.MONTH);
        int _Year   = todayDate_GC.get(GregorianCalendar.YEAR);
    
        GregorianCalendar newDate = new GregorianCalendar(_Year,_Month,_Day,0,0,0);
        zeroHourDate = newDate.getTime();
        long zeroHourDateTime = newDate.getTimeInMillis();
    

    Hope this will be helpful.

提交回复
热议问题