Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:41:30+00:00 2026-06-05T02:41:30+00:00

I have this code here: public static String AddRemoveDays(String date, int days) throws ParseException

  • 0

I have this code here:

public static String AddRemoveDays(String date, int days) throws ParseException
    {
        SimpleDateFormat k = new SimpleDateFormat("yyyyMMdd");
        Date d = k.parse(date);
        d = new Date(d.getTime() + days*86400000);
        String time = k.format(d);

        return time;
    }

It take String formed “yyyyMMdd”, and adds int days to it. It should work then the days is negative – then he would substract the days from the date. When it does it’s math, it returns String formated “yyyyMMdd”.

At least that is what it should do. It works for small numbers, but if I try to add (or remove), for example, a year (365 or -365), it returns wierd dates.

What’s the problem?
Should I do it a completley another way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:41:32+00:00Added an answer on June 5, 2026 at 2:41 am
        d = new Date(d.getTime() + days*86400000);
    

    If you multiply 86400000 by 365 integer cant hold it. Change 86400000 to Long

        d = new Date(d.getTime() + days*86400000L);
    

    and it will be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: public static Account[] LoadXml(string fileName) { Account ths = new
I have this existing code which works very well. public static T SessionGet<T>(string key)
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have this code here: public class clsDataLayer { // This function saves the
I have a web method: [System.Web.Services.WebMethod] public static string getCharacterstics(int product_id, int lang_id) {
I have this code: public static final <TypeVO extends BaseVo> List<SelectItem> populateSelectBoxForType( final Class<TypeVO>
I have this function: public static string Join(this IEnumerable<string> strings, string separator) { return
I have this code: HashMap<String, String[]> unsorted = new HashMap<String, String[]>(); String[] values =
I have this method public static List<Contact> Load(string filename) { if (!File.Exists(filename)) { throw
I have this code: private void doSomething() throws InterruptedException { WorkerThread w= new WorkerThread(this);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.