Begin forwarded message: From: lupeng0527 <[email protected]<mailto:[email protected]>> Date: July 6, 2011 21:53:55 EDT To: sergek <[email protected]<mailto:[email protected]>>, ggregory <[email protected]<mailto:[email protected]>> Subject: About "org.apache.commons.lang.time.DateUtils.getFragmentInHours ()" method
Hello Serge Knystautas, Gary Gregory: I'm Lupeng.I come from China.I'm not good at English.If you do not understand, like him to forgive. I like the Apache Software. But when I was learning commons-lang-2.5.jar,I encountered a problem. Problem Description: org.apache.commons.lang.time.DateUtils.getFragmentInHours(), API(<http://commons.apache.org/lang/api-2.5/index.html>http://commons.apache.org/lang/api-2.5/index.html): static long getFragmentInHours(Calendar calendar, int fragment) method My Example: ---------------------------------------------------------------------------------- Calendar c = Calendar.getInstance(); long h = DateUtils.getFragmentInHours(cal, Calendar.MONTH); String s = DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss"); System.out.println(s + "\t" + h); // The results: time: 2011-07-07 09:24:13 hour: 177 // However, after calculation, the results should not be a 177, the result is (6*24+9)=153 ----------------------------------------------------------------------------------- API example of official website: ----------------------------------------------------------------------------------- // 2008-01-01 07:15:10 January 1, 2008 7:15:10.538 with Calendar.MONTH as fragment will return 7 // The results: 7 ----------------------------------------------------------------------------------- When I use, the result is not the same: ----------------------------------------------------------------------------------- // Set Time Calendar c2 = Calendar.getInstance(); c2.set(Calendar.YEAR, 2008); c2.set(Calendar.MONTH, 00); c2.set(Calendar.DAY_OF_MONTH, 01); c2.set(Calendar.HOUR_OF_DAY, 7); c2.set(Calendar.MINUTE, 15); c2.set(Calendar.SECOND, 10); c2.set(Calendar.MILLISECOND, 538); long h2 = DateUtils.getFragmentInHours(c2, Calendar.MONTH); String s2 = DateFormatUtils.format(c2, "yyyy-MM-dd HH:mm:ss.SSS"); System.out.println("time: " + s2 + "\thour:" + h2); // The results: time: 2008-01-01 07:15:10.538 hour:31 // Same period of time, but the results of different ----------------------------------------------------------------------------------- Explanation: I do not know my program is correct. If the program is incorrect, please point it out! If the program is correct,my results with the API results different. So special to ask! Thank you,Waiting for your reply (please be concise language when you reply). Personal information: Name: Lupeng E-mail: <mailto:[email protected]> [email protected]<mailto:[email protected]> MSN: <mailto:[email protected]> [email protected]<mailto:[email protected]> Address: Beijing, China 2011-07-07 ________________________________ lupeng0527 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
