Here you can find the source of truncate(Calendar calendar)
Parameter | Description |
---|---|
calendar | The Calendar to truncate |
public static void truncate(Calendar calendar)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { /**/*from w w w . j a v a 2 s .co m*/ * Truncate the date removing hours, minutes, seconds and milliseconds * * @param date The {@link Date} to truncate * @return The truncated {@link Date} */ public static Date truncate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); truncate(calendar); return calendar.getTime(); } /** * Truncate the {@link Calendar} removing hours, minutes, seconds and milliseconds * * @param calendar The {@link Calendar} to truncate */ public static void truncate(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } public static Date getTime(int hour, int minutes) { return getTime(hour, minutes, true); } public static Date getTime(int hour, int minutes, Boolean is24Hour) { Calendar calendar = Calendar.getInstance(); calendar.set(is24Hour ? Calendar.HOUR_OF_DAY : Calendar.HOUR, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, 0); return calendar.getTime(); } }