How to convert an NSTimeInterval into an date with time? - iphone

I have an NSTimeInterval value, or more precisely an NSTimeInterval "since reference date". I think that's a value in seconds from 1970 or something like so. Pretty standard in most programming languages, I think.
So now I have that ugly value which the user doesn't understand, and I'd like to display a date + time. Is there a useful method or function that would do that, maybe by specifying formats or a locale as well? Maybe the iphone also has built-in support for this kind of stuff so that the date+time is displayed automatically like the user likes it in his/her settings?

You want to create an NSDate with +[NSDate dateWithTimeIntervalSince1970:]. You can then get the date's -descriptionWithLocale: or use the Date and Time Programming Guide from the iPhone library to find out more options for displaying the date.

Related

Playground simple Date() is printing value taking into cosideration my time zone

It seems that for first three lines in the screenshot the TimeZone is not applied(ok - according to documentation it should be like this), but for the last one it seem to be GMT+2 (my current time zone).
Anyone has explanation why for the last line playground is presenting date taking into consideration my system TimeZone?
Playground has its own custom rules for the gutter display. They are generally more friendly forms of the output. For another example, see UIColor, which has a radically different (and very custom) output in Playgrounds.
See the docs for CustomPlaygroundDisplayConvertible for the full list of types that get special Playgrounds handling, and how to provide custom handling for your own types.
Keep in mind, of course, that all of these descriptions are purely for informal and debugging use, and none are appropriate for actually displaying to users. See DateFormatter for how to format a date for humans. (You likely know this already, but for people reading along it can be a helpful reminder.)

Date is deprecated. Should I use it or not?

Date has many deprecated methods, i.e, getTime, getMounth, etc. Should I avoid using it?
Also, what is the difference between: Date, Calendarand DataPicker?
Date was deprecated in the JDK v1.1; in other words relatively early during the (ongoing) development of the environment. It was deprecated because of incompatibility with international time standards; while it was intended to reflect coordinated universal time (UTC) it was found that on machines that use the GMT time standard or those that do not reflect a "leap second" (an extra second once every year or two) that the Date class might not be exactly accurate.
For this reason, it is recommended that you use Calendar.get(...) instead of Date's respective methods! Also, Java8 has a UI component, DatePicker, which use's the new LocalDate class (which is a localized replacement for the deprecated Date class).

How to add NSDate+BSJSONAdditions to the BSJSON project

I need to know how to get BSJSON to handle the NSDate that is in coredata
in the json it returns null for the date, what needs to go into the category to make this work?
Assuming you're talking about http://github.com/blakeseely/bsjsonadditions, there's really no easy way to get a JSON object and dump it into NSDate. You need some intervening logic - like asserting a common date format, and then do the NSDate <-> String conversion yourself, and letting the JSON format represent the string.
Common methods for doing this are to use "# of seconds since Epoch" to represent the time, or to just fully qualify out an ISO-8601 time string. Which is easier often depends on what other systems you're working with and which they can easily convert and use. The first is accomplished super-easy with Objective-C by using NSDate dateWithTimeIntervalSince1970:
Going in and out of an ISO-8601 string is a bit more work, and you'll head into the realm of NSDateFormatter

How to print all available information of a locale?

The locale object must contain more information than apple talks about in the documentation. i.e. it must contain several date format strings. How can I print all this stuff to see where they are? Is there a method that would print out all information about an object?
Why do you believe the NS/CFLocale object has date format strings in it? I would assume these strings are stored in the NSDateFormatter class, probably as static data rather than instance data. Just my guess, but based on my experience with NSCalendar.

HTTP date format to NSDate

I have a date string (well, NSData, but that's easy to convert to a string) that's in what I believe is the format the HTTP standard uses:
Mon Apr 17 19:34:46 UTC 2006
Is there any better (i.e. less error-prone) way to parse that than specifying the format string by hand in an NSDateFormatter?
(My application is an iPhone app, but I suspect standard Cocoa solutions will work too, since NSDate and NSDateFormatter are part of Foundation.)
No, I don't think there is a better way.
If you have some outside input, you must know the format of your input beforehand, and you can only prepare for problems, i.e. a fail over parser with an alternate NSDateFormatter.