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 6919633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:00:56+00:00 2026-05-27T10:00:56+00:00

Possible Duplicate: Calculate date/time difference in java how would a future date such as

  • 0

Possible Duplicate:
Calculate date/time difference in java

how would a future date such as Sat Feb 17 2012 be converted into milliseconds in java that can then be subtracted from the current time in milliseconds to yield time remaining until that future date.

  • 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-27T10:00:57+00:00Added an answer on May 27, 2026 at 10:00 am

    The simplest technique would be to use DateFormat:

    String input = "Sat Feb 17 2012";
    Date date = new SimpleDateFormat("EEE MMM dd yyyy", Locale.ENGLISH).parse(input);
    long milliseconds = date.getTime();
    long millisecondsFromNow = milliseconds - (new Date()).getTime();
    Toast.makeText(this, "Milliseconds to future date="+millisecondsFromNow, Toast.LENGTH_SHORT).show();
    

    A more difficult technique (that basically does what DateFormat does for you) involves parsing it yourself (this would not be considered best practice):

    String input = "Sat Feb 17 2012";
    String[] myDate = input.split("\\s+");
    int year = Integer.parseInt(myDate[3]);
    String monthString = myDate[1];
    int mo = monthString.equals("Jan")? Calendar.JANUARY :
                 monthString.equals("Feb")? Calendar.FEBRUARY :
                 monthString.equals("Mar")? Calendar.MARCH :
                 monthString.equals("Apr")? Calendar.APRIL :
                 monthString.equals("May")? Calendar.MAY :
                 monthString.equals("Jun")? Calendar.JUNE :
                 monthString.equals("Jul")? Calendar.JULY :
                 monthString.equals("Aug")? Calendar.AUGUST :
                 monthString.equals("Sep")? Calendar.SEPTEMBER :
                 monthString.equals("Oct")? Calendar.OCTOBER :
                 monthString.equals("Nov")? Calendar.NOVEMBER :
                 monthString.equals("Dec")? Calendar.DECEMBER : 0;
    int day = Integer.parseInt(myDate[2]);
    Calendar c = Calendar.getInstance();
    c.set(year, mo, day);
    long then = c.getTimeInMillis();
    Time current_time = new Time();
    current_time.setToNow();
    long now = current_time.toMillis(false);
    long future = then - now;
    Date d = new Date(future);
    //TODO use d as you need.
    Toast.makeText(this, "Milliseconds to future date="+future, Toast.LENGTH_SHORT).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to calculate difference between two dates using java I'm trying something
Possible Duplicate: How to calculate the date difference between 2 dates using php Hi,,
Possible Duplicates: Calculating difference in dates in Java How can I calculate a time
Possible Duplicate: Calculating the Difference Between Two Java Date Instances In Java, I want
Possible Duplicate: How do I calculate relative time? I am searching for a custom
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicates: Difference between dates How to calculate the date difference between 2 dates
Possible Duplicate: Calculate Years, Months, weeks and Days How do I calculate difference in
Possible Duplicate: Measure execution time for a Java method I have an application by
Possible Duplicate: How to calculate how many years passed since a given date in

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.