• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Calender class doubt

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic