java.util.Date: seven days ago

前端 未结 11 1808
孤城傲影
孤城傲影 2020-12-15 04:08

I have a report created in Jasper Reports which ONLY recognizes java.util.Date\'s (not Calendar or Gregorian, etc).

Is there a way to create a date 7 days prior to t

11条回答
  •  我在风中等你
    2020-12-15 04:39

    Due to the heated discussion:

    The question may not have a proper answer w/o a designated timezone.

    below it is some code to work w/ the default (and hence deprecated) timezone that takes into account the default timezone daylight saving.

    Date date= new Date();
    date.setDate(date.getDate()-7);//date works as calendar w/ negatives
    

    While the solution does work, it is exactly as bogus as in terms of assuming the timezone.

    new Date(System.currentTimeMillis() - 10080*60000);//a week has 10080 minutes
    

    Please, don't vote for the answer.

提交回复
热议问题