aspose file tools*
The moose likes Java in General and the fly likes Getting Previous Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting Previous Date" Watch "Getting Previous Date" New topic
Author

Getting Previous Date

Rohit Dhodapkar
Ranch Hand

Joined: Apr 27, 2006
Posts: 38
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

Joined: Jun 19, 2001
Posts: 547
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

Joined: Apr 27, 2006
Posts: 38
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

Joined: Aug 16, 2005
Posts: 14420
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18985
    
    8

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Previous Date