• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

increasing the date in java as whole

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

How can we increase the date in java as whole. I mean to say that suppose my current date is 30/09/2011 then after increasing the date by 1 it should directly give 1/10/2011 not 31/09/2011 or if i increase by 2 it should give 02/10/2011 not 01/09/2011.
what i am trying is below. Is there any functions where month or year are automatically taken care off after increasing.



can any body please help me.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First thing you need to do is get your format corrected:

- For day of the month, you need to use "MM", not "mm" ("mm" is for minute)
- If you're parsing a four-digit year, use "yyyy"

Fix those, and see if the problem still occurs.
 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add Calendar.DAY_OF_MONTH instead of Calendar.DATE
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zandis Murāns wrote:Add Calendar.DAY_OF_MONTH instead of Calendar.DATE


That won't make any difference. Look up Calendar.DATE in the docs and you get:

This is a synonym for DAY_OF_MONTH.

 
Marshal
Posts: 22453
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is in your formatter. "mm" means minutes; you need "MM" for months. Beaten to it when I was testing.
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody.

The problem indeed was in selecting the format. i tried ("dd/MM/yyyy") and it is working.

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic