Here you can find the source of equalDateByDay(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | a parameter |
date2 | a parameter |
public static int equalDateByDay(Date date1, Date date2)
//package com.java2s; /*//w w w .java 2 s . c o m * Copyright (c) 2014 by Open eGovPlatform (http://http://openegovplatform.org/). * * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Calendar; import java.util.Date; public class Main { /** * This is function equalDateByDay * * Version: 1.0 * * History: * DATE AUTHOR DESCRIPTION * ------------------------------------------------- * 10-April-2013 Nam Dinh Create new * @param date1 * @param date2 * @return int */ public static int equalDateByDay(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); //so sanh theo nam if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR)) { return 1; } else if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) { return -1; } else { //so sanh theo thang if (cal1.get(Calendar.MONTH) > cal2.get(Calendar.MONTH)) { return 1; } else if (cal1.get(Calendar.MONTH) < cal2.get(Calendar.MONTH)) { return -1; } else { //so sanh theo ngay if (cal1.get(Calendar.DAY_OF_MONTH) > cal2.get(Calendar.DAY_OF_MONTH)) { return 1; } else if (cal1.get(Calendar.DAY_OF_MONTH) < cal2.get(Calendar.DAY_OF_MONTH)) { return -1; } else { return 0; } } } } }