I don’t suggest you to do this: when your time zone region enters in DST, it
will throw an exception, because there is no midnight on those days, ex:
org.joda.time.DateTimeZone dtz =
org.joda.time.DateTimeZone.forID("America/Sao_Paulo");
org.joda.time.YearMonthDay ymd = new org.joda.time.YearMonthDay(2006, 11, 5);
System.out.println(ymd.toDateMidnight());
java.lang.IllegalArgumentException: Illegal instant due to time zone offset
transition: 2006-11-05T02:00:00.000
Anibal Maffioletti de Deus
Arquiteto de Software - MTZ
Expresso Mercúrio S.A.
Tel.: +55 51 3356.5020
www.mercurio.com <http://www.mercurio.com>
Mercúrio. Ganhando tempo para você. Acelerando negócios para sua empresa.
________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bart zagers
Sent: Tuesday, September 25, 2007 3:25 PM
To: Discussion of the Joda project
Subject: Re: [Joda-interest] did a DateTime occur today?
Well I think I would use something like:
private static boolean today (DateTime dateTime)
{
DateMight today = new DateMidnight();
return today.equals(dateTime.toDateMidnight());
}
(I would certainly not use YearMonthDay as it is "replaced" with LocalDate)
On 9/24/07, Jeff White <[EMAIL PROTECTED]> wrote:
Did you try
private static boolean today (DateTime dateTime)
{
YearMonthDay today = new YearMonthDay();
return dateTime.toYearMonthDay().equals(today);
}
jeff
Ryan Propper wrote:
> Hi all,
>
> What's the fastest and cleanest way of checking whether a DateTime
> object occurred today? Right now, I have the following, but I'm
> wondering if there's something more efficient.
>
> private static boolean today(DateTime dateTime) {
> DateTime now = new DateTime();
>
> return (dateTime.getYear() == now.getYear() &&
> dateTime.getMonthOfYear () == now.getMonthOfYear() &&
> dateTime.getDayOfMonth() == now.getDayOfMonth());
> }
>
> Thanks!
>
> Ryan
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest