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

  • Home
  • SEARCH
  • 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 6048085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:25:26+00:00 2026-05-23T07:25:26+00:00

Date nowdate = new Date(); long nowms = nowdate.getTime(); long differencems = numdaysback *

  • 0
Date nowdate = new Date();
long nowms = nowdate.getTime();
long differencems = numdaysback * 24 * 60 * 60 * 1000;
long thenms = nowms - differencems;
Date thendate = new Date(thenms);

If numdaysback is 365, then I would suppose that thendate would be one year ago. but it’s not… it’s about three weeks ago?!?

NUMDAYSBACK: 365
NOWDATE: Wed Jun 22 20:31:58 SGT 2011
NOWMS: 1308745918625
DIFFERENCEMS: 1471228928
THENMS: 1307274689697
THENDATE: Sun Jun 05 19:51:29 SGT 2011
  • 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-05-23T07:25:27+00:00Added an answer on May 23, 2026 at 7:25 am

    How about:

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    Date thendate = cal.getTime();
    

    Returns the same time of day regardless of DST or leap years, is shorter and clearer…

    Generally Calendar is the way to go in such cases (unless you use a 3rd party library like Joda Time). You can use it for all kinds of calculations: add N days/hours/months/seconds, truncate time to a whole hour etc. – stuff that would be too much pain with long only.

    Regarding your original question, it seems to be a victim of integer overflow. It works if the multiplication explicitly uses long:

    long differencems = 365 * 24 * 60 * 60 * 1000L;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
var date = new Date();//Mon Mar 15 2010 12:40:05 GMT+0300 (MSK) var omg =
echo date(W,strtotime('2010-01-01')); This outputs 53. I would expect it to output 1. Can anyone
I'm receiving a date from a server in milliseconds since 1-1-1970. I then use
I would like to know how I can change the date in my selectedDate
Date.parseWeird = Date.prototype.parseWeird = function (d) { return new Date(parseInt(d.replace(/[^\-\d]/g, ), 10)); }; var
I tried the following DateTime start = Convert.ToDateTime(TextBox1.Text); DateTime end = Convert.ToDateTime(TextBox2.Text); if (DateTime.Now.Date
Date coming out of a database, need to format as mm/dd/yy For Each dr
Date and time in MySQL can be stored as DATETIME, TIMESTAMP, and INTEGER (number
[{'date': '2010-04-01', 'people': 1047, 'hits': 4522}, {'date': '2010-04-03', 'people': 617, 'hits': 2582}, {'date': '2010-04-02',

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.