Here you can find the source of isSameDay(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | the first date |
date2 | the second date |
public static boolean isSameDay(Date date1, Date date2)
//package com.java2s; /**//from w w w.j a v a 2 s . c o m * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ import java.util.*; public class Main { /** * Checks if two dates are the same day * @param date1 the first date * @param date2 the second date * @return true if dates are same day */ public static boolean isSameDay(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; } Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH); } }