Created
November 7, 2010 13:48
-
-
Save andrerocker/666132 to your computer and use it in GitHub Desktop.
Java Encontrar Primeiro e Ultimo Dia de Uma Semana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.braincoretechnology.rules.util; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
public class DateUtil | |
{ | |
public static Date resolvePrimeiroUltimo(Date data, boolean isPrimeiro) | |
{ | |
GregorianCalendar calendar = new GregorianCalendar(); | |
calendar.setFirstDayOfWeek(Calendar.MONDAY); | |
calendar.setTime(data); | |
if(isPrimeiro) | |
{ | |
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); | |
calendar.set(Calendar.AM_PM, Calendar.AM); | |
calendar.set(Calendar.HOUR, 0); | |
calendar.set(Calendar.MINUTE, 0); | |
calendar.set(Calendar.SECOND, 0); | |
} | |
else | |
{ | |
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); | |
calendar.set(Calendar.AM_PM, Calendar.PM); | |
calendar.set(Calendar.HOUR, 11); | |
calendar.set(Calendar.MINUTE, 59); | |
calendar.set(Calendar.SECOND, 59); | |
} | |
return calendar.getTime(); | |
} | |
public static void main(String[] args) | |
{ | |
Date primeiroDia = resolvePrimeiroUltimo(new Date(), true); | |
Date ultimoDia = resolvePrimeiroUltimo(new Date(), false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment