Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    public static boolean isDatesInSameWeek(long lhsDate, long rhsDate) {
        Calendar lhsCalendar = getCalendarWithTime(lhsDate);
        int lhsWeek = lhsCalendar.get(Calendar.WEEK_OF_YEAR);
        int lhsYear = lhsCalendar.get(Calendar.YEAR);

        Calendar rhsCalendar = getCalendarWithTime(rhsDate);
        int rhsWeek = rhsCalendar.get(Calendar.WEEK_OF_YEAR);
        int rhsYear = rhsCalendar.get(Calendar.YEAR);

        return (lhsWeek == rhsWeek) && (lhsYear == rhsYear);
    }

    public static Calendar getCalendarWithTime(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        return calendar;
    }
}