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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:41:12+00:00 2026-05-23T17:41:12+00:00

What might be the Android equivalent of the following iPhone code? NSCalendar *calender =

  • 0

What might be the Android equivalent of the following iPhone code?

NSCalendar *calender = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
int units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calender components:units fromDate:[NSDate date] toDate:destinationDate options:0];

I am trying to do a date countdown to show the number of years, months, days, hours, minutes and seconds in a consecutive manner, not show the years, months, days, hours, minutes and seconds as a whole.

I have this, but I cannot get the hours, minutes and seconds. When I play with the hours, I keep getting hours in the days, not hours left.

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(myDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        long nat = Math.round(date.getTime() / 1000);
        long totaldifference = Math.abs(d1-d2);

        long date_diff = Math.round(totaldifference/(24*3600));
        //year
        double year2 = Math.floor(date_diff/365);
        date_diff-=year2*365;

        double month2 = Math.floor(date_diff/30.5);
        date_diff-=month2*30.5;

        long day2 = date_diff;
  • 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-23T17:41:12+00:00Added an answer on May 23, 2026 at 5:41 pm

    To get a Calendar, you can do this:

    Calendar cal = Calendar.getInstance()
    

    Doing it this way will initialize it to the current date and time. Check the documentation if you need to set it to a different date or time.

    To get the year, month, day, and so on, you can do this:

    int year = cal.get(Calendar.YEAR)
    int month = cal.get(Calendar.MONTH)
    int day = cal.get(Calendar.DATE)
    

    To “count down” on that, you can add a negative of whatever unit you want to count down in:

    cal.add(Calendar.SECOND, -1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

might be a silly question nonetheless: I'm playing around with the following code: $a='a';
As you might know, Android's SDK features a AsyncTask class which allows for code
This might seem a stupid question, but I am following the Android guide on
noob Android/JSON person here. I hope someone might help me? I've looked and looked
I am trying to achieve the following with Android : when the app is
I might not like it, but the number of unofficial Android devices is growing
Well, I might as well post the fist question. Does AndParcel allow Android Library
I'm developing an Android application that might be used at night. Therefor, I need
Can anyone please tell me why this might fail: afeder@ubuntu:~/android/toolchain/sysroot$ ls $PKG_CONFIG_SYSROOT_DIR/usr/local/lib/pkgconfig/mozjs185.pc /home/afeder/android/toolchain/sysroot/usr/local/lib/pkgconfig/mozjs185.pc afeder@ubuntu:~/android/toolchain/sysroot$
I'm new to Android development, so I might be missing something obvious. I want

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.