Here you can find the source of compareDay(Date first, Date second)
Description:Get Monday of the week the day specified by parameter belongs to
Parameter | Description |
---|---|
Date | date any date |
public static int compareDay(Date first, Date second)
//package com.java2s; /*/* ww w . ja v a 2s. com*/ * $RCSfile: DatetimeUtil,v $$ * $Revision: 1.0 $ * $Date: 2011 $ * * Copyright (C) 2011 GyTech, Inc. All rights reserved. * * This software is the proprietary information of GyTech, Inc. * Use is subject to license terms. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /** *<p>Description:Get Monday of the week the day specified by parameter belongs to</p> * @param Date date any date * @return boolean */ public static int compareDay(String timeComparing, String timeCompared, String format) { Date timeComparingDate = stringToDate(timeComparing, format); Date timeComparedDate = stringToDate(timeComparing, format); return compareDay(timeComparingDate, timeComparedDate); } /** *<p>Description:Get Monday of the week the day specified by parameter belongs to</p> * @param Date date any date * @return boolean */ public static int compareDay(Date first, Date second) { Calendar cf = Calendar.getInstance(); cf.setTime(first); Calendar cs = Calendar.getInstance(); cs.setTime(second); int offset = (cf.get(Calendar.YEAR) - cs.get(Calendar.YEAR)) * 12 * 30 + (cf.get(Calendar.MONTH) - cs.get(Calendar.MONTH)) * 30 + (cf.get(Calendar.DATE) - cs.get(Calendar.DATE)); return offset; } /** * <p>Description:Get the date according to specific String content * The default format is "yyyy-MM-dd" * </p> * @param String * @return Date */ public static Date stringToDate(String datecontent, String format) { if (format == null || format.equals("")) format = "yyyy-MM-dd"; try { SimpleDateFormat bartDateFormat = new SimpleDateFormat(format); Date date = bartDateFormat.parse(datecontent); return date; } catch (ParseException pe) { @SuppressWarnings("unused") String message = "Exception occurs in Parse progress."; } catch (Exception e) { @SuppressWarnings("unused") String message = "Exception occurs during the string converting to Date."; } return null; } }