 |
 |
converting an integer of seconds into NSDate
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
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
|
|
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'."
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Oct 2001
Status:
Offline
|
|
now we're talking. that is exactly what i want to accomplish. once again rickster to the rescue.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|