Here you can find the source of getLastTimeInDay(Date day)
public static Date getLastTimeInDay(Date day)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { public static Date getLastTimeInDay(Date day) { Calendar date = Calendar.getInstance(); date.setTime(getFirstTimeInDay(day)); date.add(Calendar.DAY_OF_YEAR, 1); date.add(Calendar.SECOND, -1); return date.getTime(); }/* w w w . ja v a 2s .co m*/ public static Date getFirstTimeInDay(Date day) { Calendar date = Calendar.getInstance(); date.setTime(day); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); return date.getTime(); } public static String getTime() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); String min; min = dateString.substring(14, 16); return min; } }