Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > converting an integer of seconds into NSDate

converting an integer of seconds into NSDate
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 3, 2002, 07:00 PM
 
if I have an integer of say 347838438 seconds, how can I convert this into an NSDate such that when my NSTable displays it, it is displayed like:

DD:HH:MM:SS

As it is now, Im converting seconds into DD:HH:MM:SS manually and returning a string, but when I sort my table, the entries are sorted incorrectly. Im not sure, but I believe NSDates are key because they can be more easily compared. Any ideas?
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Oct 3, 2002, 08:58 PM
 
It depends on what the 347838438 seconds represent...
you can use the function:
initWithTimeIntervalSinceReferenceDate:
to create an NSDate 347838438 seconds from Jan 1, 2001...

or
initWithTimeInterval:sinceDate:
to initialize NSDate with seconds from an arbitrary date.
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 3, 2002, 09:03 PM
 
the integer represents the length of an mp3. It sounds like Im barking up the wrong tree, in my trying to use NSDate to do the math for me. Its just that i was thinking that NSDate would be alot faster than my manual conversion method. I was hoping that also a side benefit would be that I could sort them in the table better using compare:.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Oct 4, 2002, 12:21 AM
 
Originally posted by 3R1C:
the integer represents the length of an mp3. It sounds like Im barking up the wrong tree, in my trying to use NSDate to do the math for me. Its just that i was thinking that NSDate would be alot faster than my manual conversion method. I was hoping that also a side benefit would be that I could sort them in the table better using compare:.
It sounds to me like your problem is that you don't want a date. A date is a specific point in time (e.g. 9:25:41 a.m., January 19, 2003). A number of seconds isn't a date; it's an interval, an amount of time.

But why don't you just use the raw integer for your comparisons? That sounds simple enough to me, though I'm not really clear on the details here.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 4, 2002, 01:11 AM
 
As stated above, I already am doing the conversion manually with the integer. It IS very simple, the problem is that since its a string, it doesnt sort correctly.
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Oct 4, 2002, 01:56 AM
 
Ah. Probably the best solution here is to use a formatter. Write a subclass of NSFormatter that can make HH:MM:SS strings from integer number of seconds, stick that on your table column, and then use the actual seconds amount as the objectValue for each cell. You can then have the best of both worlds -- sorting and other model operations are done on the accurate number, but the display is in a friendly format.
Rick Roe
icons.cx | weblog
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 4, 2002, 02:32 AM
 
now we're talking. that is exactly what i want to accomplish. once again rickster to the rescue.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2