Here you can find the source of toMidnight(long time, TimeZone tz)
public static final long toMidnight(long time, TimeZone tz)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.TimeZone; public class Main { private static final long MILLIS_IN_DAY = 86400000l; public static final long toMidnight(long time, TimeZone tz) { return toMidnight(time, 0, tz); }//from www .java 2 s . c o m public static final long toMidnight(long time, int nDays, TimeZone tz) { Calendar c = Calendar.getInstance(tz); c.setTimeInMillis(time + nDays * MILLIS_IN_DAY); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); return c.getTimeInMillis(); } }