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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:36:10+00:00 2026-05-26T13:36:10+00:00

How can I convert a NSTimeInterval to NSDate ? Think of it like a

  • 0

How can I convert a NSTimeInterval to NSDate? Think of it like a stopwatch. I want the initial date to be 00:00:00, and I have a NSTimeInterval of X seconds.

I need to do it like this because the NSTimeInterval needs to be converted to an int by using lround to round up, then converted to a NSDate to use the NSDateFormatter to throw it into a string.

  • 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-26T13:36:11+00:00Added an answer on May 26, 2026 at 1:36 pm

    An NSTimeInterval, as its name, um, implies, doesn’t represent the same thing as an NSDate. An NSDate is a moment in time. A time interval is a stretch of time. To get a point from an interval, you have to have another point. Your question is like asking “How do I convert 12 inches to a spot on this board I’m cutting?” Well, 12 inches, starting from where?

    You need to pick a reference date. This will most likely be the NSDate representing the time that you started your counter. Then you can use +[NSDate dateWithTimeInterval:sinceDate:] or -[NSDate dateByAddingTimeInterval:]

    That said, I’m pretty sure you’re thinking about this backwards. You’re trying to display time elapsed since some starting point, i.e., the interval, not the current time. Every time you update the display, you should just be using the new interval. For example (assuming you have a timer firing periodically to do the update):

    - (void) updateElapsedTimeDisplay: (NSTimer *)tim {
    
        // You could also have stored the start time using
        // CFAbsoluteTimeGetCurrent()
        NSTimeInterval elapsedTime = [startDate timeIntervalSinceNow];
    
        // Divide the interval by 3600 and keep the quotient and remainder
        div_t h = div(elapsedTime, 3600);
        int hours = h.quot;
        // Divide the remainder by 60; the quotient is minutes, the remainder
        // is seconds.
        div_t m = div(h.rem, 60);
        int minutes = m.quot;
        int seconds = m.rem;
    
        // If you want to get the individual digits of the units, use div again
        // with a divisor of 10.
    
        NSLog(@"%d:%d:%d", hours, minutes, seconds);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSDate *newDate=[newDate dateByAddingTimeInterval:difference]; Now I want to convert this newDate to NStimeInterval. How can
You can convert a negative number to positive like this: int myInt = System.Math.Abs(-5);
On Linux you can convert a date like 2010-10-02 to a unix timestamp in
I want to convert my Local date ([NSDate date]) to GMT to create a
In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column)
So I figured out I can convert an image to grayscale like this: public
Now I can convert a hex string to rgb color like this: // Input
I have this XML and just wondering how I can convert into C# class
Is there any way how can i convert a nstimeinterval type value to a
How i can convert number 20020415 to date 15.04.2002. I am working in Microsoft

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.