File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calender class doubt

 
Divya Gehlot
Ranch Hand
Posts: 243
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any one explain me following Calender example what
cal.roll(Calendar.DAY_OF_YEAR, true);
will return and whats the use of that.
why second println give IllegalArgumentException.

Thanks in advance
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one explain me following Calender example what
cal.roll(Calendar.DAY_OF_YEAR, true);
will return and whats the use of that.


this is straight from Java specification about Calendar class::


roll
public abstract void roll(int field,boolean up)::
Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields. For example, to roll the current date up by one day, you can achieve it by calling:

roll(Calendar.DATE, true).

When rolling on the year or Calendar.YEAR field, it will roll the year value in the
range between 1 and the value returned by calling getMaximum(Calendar.YEAR). When rolling on the month or Calendar.MONTH field,
other fields like date might conflict and, need to be changed.
For instance, rolling the month on the date 01/31/96 will result in 02/29/96. When rolling on the hour-in-day or Calendar.HOUR_OF_DAY field, it will roll the hour value in the range between 0 and 23, which is zero-based.




why second println give IllegalArgumentException.
System.out.println(new SimpleDateFormat("DD-MM-YYYY").format(cal.getTime()))


pattern should be dd-mm yy and not dd-mm-yyyy

for more click on this link::

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
 
Deepak Jain
Ranch Hand
Posts: 637
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SimpleDateFormat(String pattern) throws IllegalArgumentException if the given pattern is invalid, In your example
new SimpleDateFormat("DD-MM-YYYY") The pattern is invalid because it has "Y"

Also SimpleDateFormat("Y") will throw IllegalArgumentException .
I am not sure how and where are the valid pattenrs defined?

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html#SimpleDateFormat(java.lang.String)

Thanks
Deepak
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak, please check your private messages. You can see them by clicking on "My Profile" at the top right of the page.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic