Formatting 00:00 January 1 1900

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Formatting 00:00 January 1 1900

nino martinez wael
Hi 

Im having some issues doing this:

@Test
public void testJoda(){
DateTimeFormatter withPivotYear = DateTimeFormat.forPattern("HH:mm").withLocale(new Locale("da_DK"));
Calendar instance = Calendar.getInstance();
instance.set(1900, 0, 1, 0, 0,0);
Date dateModified=instance.getTime();
DateTime dt = new DateTime(dateModified);

String result=withPivotYear.print(dt);
Assert.assertTrue("00:00".equalsIgnoreCase(result));

}
the contents of dt becomes 1899-12-31T23:09:21.857+00:09:21 thus the result becomes 23:09, whats wrong?

--
Best regards / Med venlig hilsen 
Nino Martinez


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Formatting 00:00 January 1 1900

jodastephen
On 17 April 2012 07:12, nino martinez wael <[hidden email]> wrote:

> @Test
> public void testJoda(){
> DateTimeFormatter withPivotYear =
> DateTimeFormat.forPattern("HH:mm").withLocale(new Locale("da_DK"));
> Calendar instance = Calendar.getInstance();
> instance.set(1900, 0, 1, 0, 0,0);
> Date dateModified=instance.getTime();
> DateTime dt = new DateTime(dateModified);
>
> String result=withPivotYear.print(dt);
> Assert.assertTrue("00:00".equalsIgnoreCase(result));
>
> }
> the contents of dt becomes 1899-12-31T23:09:21.857+00:09:21 thus the result
> becomes 23:09, whats wrong?

Every time you mix JDK classes and Joda-Time classes, this FAQ applies
http://joda-time.sourceforge.net/faq.html#wrongoffset

In your case, the 1900 date is probably before when daylight savings
started. For those dates, JodaTime uses LMT (Local Mean Time) when the
JDK uses the current fixed offset. This difference account for your
result.

Stephen

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Formatting 00:00 January 1 1900

Steve Hathaway
In reply to this post by nino martinez wael
On 4/16/2012 11:12 PM, nino martinez wael wrote:
Hi 

Im having some issues doing this:

@Test
public void testJoda(){
DateTimeFormatter withPivotYear = DateTimeFormat.forPattern("HH:mm").withLocale(new Locale("da_DK"));
Calendar instance = Calendar.getInstance();
instance.set(1900, 0, 1, 0, 0,0);
Date dateModified=instance.getTime();
DateTime dt = new DateTime(dateModified);

String result=withPivotYear.print(dt);
Assert.assertTrue("00:00".equalsIgnoreCase(result));

}
the contents of dt becomes 1899-12-31T23:09:21.857+00:09:21 thus the result becomes 23:09, whats wrong?

--
Best regards / Med venlig hilsen 
Nino Martinez



------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev


_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Is January (month = 1 or 0)?
Is the local timezone: -01 hours?

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Formatting 00:00 January 1 1900

jodastephen
On 17 April 2012 11:50, Steve Hathaway <[hidden email]> wrote:
> Is January (month = 1 or 0)?

January is 1, December is 12

> Is the local timezone: -01 hours?

The local time zone is whatever you're machine has.

System.out.println(TimeZone.getDefault());  // Java's time zone
System.out.println(DateTimeZone.getDefault());  // Joda's time zone

Both time-zone classes have methods to get the offset at a particular instant.

Stephen

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Formatting 00:00 January 1 1900

nino martinez wael
But how do I fix it?


2012/4/17 Stephen Colebourne <[hidden email]>
On 17 April 2012 11:50, Steve Hathaway <[hidden email]> wrote:
> Is January (month = 1 or 0)?

January is 1, December is 12

> Is the local timezone: -01 hours?

The local time zone is whatever you're machine has.

System.out.println(TimeZone.getDefault());  // Java's time zone
System.out.println(DateTimeZone.getDefault());  // Joda's time zone

Both time-zone classes have methods to get the offset at a particular instant.

Stephen

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



--
Best regards / Med venlig hilsen 
Nino Martinez


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...