This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Previous Date

 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get a date which is n days previous to the current date. I want to do it without using the Calender Objet but just by using java.util.Date.

Can any body please help.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to do this without Calendar ?

Date has a constructor taking a long argument which is the number of milliseconds sinse 1.1.1970 (see javadoc). And if you have a Date X where you want to subtract 1 day, then its:
oldDate in millis - 1000 * 60 * 60 * 24

make sure the multiplication does not exceed the int range!


pascal
 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to do this stuff in the java script .Can you please advice me how to do it?.

Thanks in advance
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JavaScript, not in Java?

The forums here are about Java. The JavaScript language is something different than Java, even though the names are similar.

If you have a question about JavaScript, you should ask your question somewhere else, in a forum about JavaScript.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We do have an HTML and Javascript forum here, which the post could be moved to. But Rohit originally asked about Java, then about Javascript. So maybe there is a question about which one Rohit should be using?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic