Java Doc for DateUtils.java in  » Library » Apache-common-lang » org » apache » commons » lang » time » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang.time 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.lang.time.DateUtils

DateUtils
public class DateUtils (Code)

A suite of utilities surrounding the use of the java.util.Calendar and java.util.Date object.


author:
   Serge Knystautas
author:
   Stephen Colebourne
author:
   Janek Bogucki
author:
   Gary Gregory
author:
   Phil Steitz
since:
   2.0
version:
   $Id: DateUtils.java 437554 2006-08-28 06:21:41Z bayard $

Inner Class :static class DateIterator implements Iterator

Field Summary
final public static  intMILLIS_IN_DAY
     Number of milliseconds in a standard day.
final public static  intMILLIS_IN_HOUR
     Number of milliseconds in a standard hour.
final public static  intMILLIS_IN_MINUTE
     Number of milliseconds in a standard minute.
final public static  intMILLIS_IN_SECOND
     Number of milliseconds in a standard second.
final public static  longMILLIS_PER_DAY
     Number of milliseconds in a standard day.
final public static  longMILLIS_PER_HOUR
     Number of milliseconds in a standard hour.
final public static  longMILLIS_PER_MINUTE
     Number of milliseconds in a standard minute.
final public static  longMILLIS_PER_SECOND
     Number of milliseconds in a standard second.
final public static  intRANGE_MONTH_MONDAY
     A month range, the week starting on Monday.
final public static  intRANGE_MONTH_SUNDAY
     A month range, the week starting on Sunday.
final public static  intRANGE_WEEK_CENTER
     A week range, centered around the day focused.
final public static  intRANGE_WEEK_MONDAY
     A week range, starting on Monday.
final public static  intRANGE_WEEK_RELATIVE
     A week range, starting on the day focused.
final public static  intRANGE_WEEK_SUNDAY
     A week range, starting on Sunday.
final public static  intSEMI_MONTH
     This is half a month, so this represents whether a date is in the top or bottom half of the month.
final public static  TimeZoneUTC_TIME_ZONE
     The UTC time zone (often referred to as GMT).

Constructor Summary
public  DateUtils()
    

DateUtils instances should NOT be constructed in standard programming.


Method Summary
public static  Dateadd(Date date, int calendarField, int amount)
     Adds to a date returning a new object.
public static  DateaddDays(Date date, int amount)
     Adds a number of days to a date returning a new object.
public static  DateaddHours(Date date, int amount)
     Adds a number of hours to a date returning a new object.
public static  DateaddMilliseconds(Date date, int amount)
     Adds a number of milliseconds to a date returning a new object.
public static  DateaddMinutes(Date date, int amount)
     Adds a number of minutes to a date returning a new object.
public static  DateaddMonths(Date date, int amount)
     Adds a number of months to a date returning a new object.
public static  DateaddSeconds(Date date, int amount)
     Adds a number of seconds to a date returning a new object.
public static  DateaddWeeks(Date date, int amount)
     Adds a number of weeks to a date returning a new object.
public static  DateaddYears(Date date, int amount)
     Adds a number of years to a date returning a new object.
public static  booleanisSameDay(Date date1, Date date2)
    

Checks if two date objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.

public static  booleanisSameDay(Calendar cal1, Calendar cal2)
    

Checks if two calendar objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.

public static  booleanisSameInstant(Date date1, Date date2)
    
public static  booleanisSameInstant(Calendar cal1, Calendar cal2)
    
public static  booleanisSameLocalTime(Calendar cal1, Calendar cal2)
    

Checks if two calendar objects represent the same local time.

This method compares the values of the fields of the two objects.

public static  Iteratoriterator(Date focus, int rangeStyle)
    

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.

This method provides an iterator that returns Calendar objects. The days are progressed using Calendar.add(intint) .


Parameters:
  focus - the date to work with, not null
Parameters:
  rangeStyle - the style constant to use.
public static  Iteratoriterator(Calendar focus, int rangeStyle)
    

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.

This method provides an iterator that returns Calendar objects. The days are progressed using Calendar.add(intint) .


Parameters:
  focus - the date to work with
Parameters:
  rangeStyle - the style constant to use.
public static  Iteratoriterator(Object focus, int rangeStyle)
    

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.


Parameters:
  focus - the date to work with, eitherDate or Calendar
Parameters:
  rangeStyle - the style constant to use.
public static  DateparseDate(String str, String[] parsePatterns)
    

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn.

public static  Dateround(Date date, int field)
    

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000.

public static  Calendarround(Calendar date, int field)
    

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000.

public static  Dateround(Object date, int field)
    

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000.

public static  Datetruncate(Date date, int field)
    

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.

public static  Calendartruncate(Calendar date, int field)
    

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.

public static  Datetruncate(Object date, int field)
    

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.


Field Detail
MILLIS_IN_DAY
final public static int MILLIS_IN_DAY(Code)
Number of milliseconds in a standard day.



MILLIS_IN_HOUR
final public static int MILLIS_IN_HOUR(Code)
Number of milliseconds in a standard hour.



MILLIS_IN_MINUTE
final public static int MILLIS_IN_MINUTE(Code)
Number of milliseconds in a standard minute.



MILLIS_IN_SECOND
final public static int MILLIS_IN_SECOND(Code)
Number of milliseconds in a standard second.



MILLIS_PER_DAY
final public static long MILLIS_PER_DAY(Code)
Number of milliseconds in a standard day.
since:
   2.1



MILLIS_PER_HOUR
final public static long MILLIS_PER_HOUR(Code)
Number of milliseconds in a standard hour.
since:
   2.1



MILLIS_PER_MINUTE
final public static long MILLIS_PER_MINUTE(Code)
Number of milliseconds in a standard minute.
since:
   2.1



MILLIS_PER_SECOND
final public static long MILLIS_PER_SECOND(Code)
Number of milliseconds in a standard second.
since:
   2.1



RANGE_MONTH_MONDAY
final public static int RANGE_MONTH_MONDAY(Code)
A month range, the week starting on Monday.



RANGE_MONTH_SUNDAY
final public static int RANGE_MONTH_SUNDAY(Code)
A month range, the week starting on Sunday.



RANGE_WEEK_CENTER
final public static int RANGE_WEEK_CENTER(Code)
A week range, centered around the day focused.



RANGE_WEEK_MONDAY
final public static int RANGE_WEEK_MONDAY(Code)
A week range, starting on Monday.



RANGE_WEEK_RELATIVE
final public static int RANGE_WEEK_RELATIVE(Code)
A week range, starting on the day focused.



RANGE_WEEK_SUNDAY
final public static int RANGE_WEEK_SUNDAY(Code)
A week range, starting on Sunday.



SEMI_MONTH
final public static int SEMI_MONTH(Code)
This is half a month, so this represents whether a date is in the top or bottom half of the month.



UTC_TIME_ZONE
final public static TimeZone UTC_TIME_ZONE(Code)
The UTC time zone (often referred to as GMT).




Constructor Detail
DateUtils
public DateUtils()(Code)

DateUtils instances should NOT be constructed in standard programming. Instead, the class should be used as DateUtils.parse(str);.

This constructor is public to permit tools that require a JavaBean instance to operate.





Method Detail
add
public static Date add(Date date, int calendarField, int amount)(Code)
Adds to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  calendarField - the calendar field to add to
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addDays
public static Date addDays(Date date, int amount)(Code)
Adds a number of days to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addHours
public static Date addHours(Date date, int amount)(Code)
Adds a number of hours to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addMilliseconds
public static Date addMilliseconds(Date date, int amount)(Code)
Adds a number of milliseconds to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addMinutes
public static Date addMinutes(Date date, int amount)(Code)
Adds a number of minutes to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addMonths
public static Date addMonths(Date date, int amount)(Code)
Adds a number of months to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addSeconds
public static Date addSeconds(Date date, int amount)(Code)
Adds a number of seconds to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addWeeks
public static Date addWeeks(Date date, int amount)(Code)
Adds a number of weeks to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



addYears
public static Date addYears(Date date, int amount)(Code)
Adds a number of years to a date returning a new object. The original date object is unchanged.
Parameters:
  date - the date, not null
Parameters:
  amount - the amount to add, may be negative the new date object with the amount added
throws:
  IllegalArgumentException - if the date is null



isSameDay
public static boolean isSameDay(Date date1, Date date2)(Code)

Checks if two date objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.


Parameters:
  date1 - the first date, not altered, not null
Parameters:
  date2 - the second date, not altered, not null true if they represent the same day
throws:
  IllegalArgumentException - if either date is null
since:
   2.1



isSameDay
public static boolean isSameDay(Calendar cal1, Calendar cal2)(Code)

Checks if two calendar objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.


Parameters:
  cal1 - the first calendar, not altered, not null
Parameters:
  cal2 - the second calendar, not altered, not null true if they represent the same day
throws:
  IllegalArgumentException - if either calendar is null
since:
   2.1



isSameInstant
public static boolean isSameInstant(Date date1, Date date2)(Code)

Checks if two date objects represent the same instant in time.

This method compares the long millisecond time of the two objects.


Parameters:
  date1 - the first date, not altered, not null
Parameters:
  date2 - the second date, not altered, not null true if they represent the same millisecond instant
throws:
  IllegalArgumentException - if either date is null
since:
   2.1



isSameInstant
public static boolean isSameInstant(Calendar cal1, Calendar cal2)(Code)

Checks if two calendar objects represent the same instant in time.

This method compares the long millisecond time of the two objects.


Parameters:
  cal1 - the first calendar, not altered, not null
Parameters:
  cal2 - the second calendar, not altered, not null true if they represent the same millisecond instant
throws:
  IllegalArgumentException - if either date is null
since:
   2.1



isSameLocalTime
public static boolean isSameLocalTime(Calendar cal1, Calendar cal2)(Code)

Checks if two calendar objects represent the same local time.

This method compares the values of the fields of the two objects. In addition, both calendars must be the same of the same type.


Parameters:
  cal1 - the first calendar, not altered, not null
Parameters:
  cal2 - the second calendar, not altered, not null true if they represent the same millisecond instant
throws:
  IllegalArgumentException - if either date is null
since:
   2.1



iterator
public static Iterator iterator(Date focus, int rangeStyle)(Code)

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.

This method provides an iterator that returns Calendar objects. The days are progressed using Calendar.add(intint) .


Parameters:
  focus - the date to work with, not null
Parameters:
  rangeStyle - the style constant to use. Must be one ofDateUtils.RANGE_MONTH_SUNDAY, DateUtils.RANGE_MONTH_MONDAY,DateUtils.RANGE_WEEK_SUNDAY,DateUtils.RANGE_WEEK_MONDAY,DateUtils.RANGE_WEEK_RELATIVE,DateUtils.RANGE_WEEK_CENTER the date iterator, which always returns Calendar instances
throws:
  IllegalArgumentException - if the date is null
throws:
  IllegalArgumentException - if the rangeStyle is invalid



iterator
public static Iterator iterator(Calendar focus, int rangeStyle)(Code)

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.

This method provides an iterator that returns Calendar objects. The days are progressed using Calendar.add(intint) .


Parameters:
  focus - the date to work with
Parameters:
  rangeStyle - the style constant to use. Must be one ofDateUtils.RANGE_MONTH_SUNDAY, DateUtils.RANGE_MONTH_MONDAY,DateUtils.RANGE_WEEK_SUNDAY,DateUtils.RANGE_WEEK_MONDAY,DateUtils.RANGE_WEEK_RELATIVE,DateUtils.RANGE_WEEK_CENTER the date iterator
throws:
  IllegalArgumentException - if the date is null
throws:
  IllegalArgumentException - if the rangeStyle is invalid



iterator
public static Iterator iterator(Object focus, int rangeStyle)(Code)

This constructs an Iterator over each day in a date range defined by a focus date and range style.

For instance, passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return an Iterator that starts with Sunday, June 30, 2002 and ends with Saturday, August 3, 2002, returning a Calendar instance for each intermediate day.


Parameters:
  focus - the date to work with, eitherDate or Calendar
Parameters:
  rangeStyle - the style constant to use. Must be one of the rangestyles listed for the DateUtils.iterator(Calendar,int) method. the date iterator
throws:
  IllegalArgumentException - if the dateis null
throws:
  ClassCastException - if the object type isnot a Date or Calendar



parseDate
public static Date parseDate(String str, String[] parsePatterns) throws ParseException(Code)

Parses a string representing a date by trying a variety of different parsers.

The parse will try each parse pattern in turn. A parse is only deemed sucessful if it parses the whole of the input string. If no parse patterns match, a ParseException is thrown.


Parameters:
  str - the date to parse, not null
Parameters:
  parsePatterns - the date format patterns to use, see SimpleDateFormat, not null the parsed date
throws:
  IllegalArgumentException - if the date string or pattern array is null
throws:
  ParseException - if none of the date patterns were suitable



round
public static Date round(Date date, int field)(Code)

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000.

For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:

  • March 30, 2003 01:10 rounds to March 30, 2003 01:00
  • March 30, 2003 01:40 rounds to March 30, 2003 03:00
  • March 30, 2003 02:10 rounds to March 30, 2003 03:00
  • March 30, 2003 02:40 rounds to March 30, 2003 04:00


Parameters:
  date - the date to work with
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date
throws:
  IllegalArgumentException - if the date is null
throws:
  ArithmeticException - if the year is over 280 million



round
public static Calendar round(Calendar date, int field)(Code)

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000.

For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:

  • March 30, 2003 01:10 rounds to March 30, 2003 01:00
  • March 30, 2003 01:40 rounds to March 30, 2003 03:00
  • March 30, 2003 02:10 rounds to March 30, 2003 03:00
  • March 30, 2003 02:40 rounds to March 30, 2003 04:00


Parameters:
  date - the date to work with
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date (a different object)
throws:
  IllegalArgumentException - if the date is null
throws:
  ArithmeticException - if the year is over 280 million



round
public static Date round(Object date, int field)(Code)

Round this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000. If this was passed with MONTH, it would return 1 April 2002 0:00:00.000.

For a date in a timezone that handles the change to daylight saving time, rounding to Calendar.HOUR_OF_DAY will behave as follows. Suppose daylight saving time begins at 02:00 on March 30. Rounding a date that crosses this time would produce the following values:

  • March 30, 2003 01:10 rounds to March 30, 2003 01:00
  • March 30, 2003 01:40 rounds to March 30, 2003 03:00
  • March 30, 2003 02:10 rounds to March 30, 2003 03:00
  • March 30, 2003 02:40 rounds to March 30, 2003 04:00


Parameters:
  date - the date to work with, either Date or Calendar
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date
throws:
  IllegalArgumentException - if the date is null
throws:
  ClassCastException - if the object type is not a Dateor Calendar
throws:
  ArithmeticException - if the year is over 280 million



truncate
public static Date truncate(Date date, int field)(Code)

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.


Parameters:
  date - the date to work with
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date
throws:
  IllegalArgumentException - if the date is null
throws:
  ArithmeticException - if the year is over 280 million



truncate
public static Calendar truncate(Calendar date, int field)(Code)

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.


Parameters:
  date - the date to work with
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date (a different object)
throws:
  IllegalArgumentException - if the date is null
throws:
  ArithmeticException - if the year is over 280 million



truncate
public static Date truncate(Object date, int field)(Code)

Truncate this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000. If this was passed with MONTH, it would return 1 Mar 2002 0:00:00.000.


Parameters:
  date - the date to work with, either Dateor Calendar
Parameters:
  field - the field from Calendaror SEMI_MONTH the rounded date
throws:
  IllegalArgumentException - if the dateis null
throws:
  ClassCastException - if the object type is not aDate or Calendar
throws:
  ArithmeticException - if the year is over 280 million



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.