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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:36:59+00:00 2026-06-11T18:36:59+00:00

I am getting date/time as JSON that I am storing as a series of

  • 0

I am getting date/time as JSON that I am storing as a series of NSArray objects.

The JSON format is as follows:

"created_at" = "2012-09-21T12:41:26-0500"

How do I sort my array so that the latest items are at the very top.

Thank You

  • 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-06-11T18:37:00+00:00Added an answer on June 11, 2026 at 6:37 pm

    The first thing you need to do is convert the date string into an NSDate object for every one of the items inside your original array, this is key, as the system knows how to compare dates, but not ISO8601 strings.

    There are several ways to do the conversion, in the example bellow I am using a custom category on NSDate, you can use the answer to this question for the conversion: Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?,

    Once you have NSDates, sorting is extremely easy using an NSSortDescriptor as shown bellow:

    NSArray *originalArray = @[
        @{@"created_at" : [NSDate dateFromISO8601String:@"2012-09-21T12:41:26-0500"]},
        @{@"created_at" : [NSDate dateFromISO8601String:@"2012-07-21T12:41:26-0500"]},
        @{@"created_at" : [NSDate dateFromISO8601String:@"2012-06-21T12:41:26-0500"]},
        @{@"created_at" : [NSDate dateFromISO8601String:@"2012-10-21T12:41:26-0500"]}
        ];
    
    NSSortDescriptor *sortDescriptor = 
        [[NSSortDescriptor alloc] initWithKey:@"created_at" ascending:NO];
    NSArray *sortedArray = 
        [originalArray sortedArrayUsingDescriptors:@[sortDescriptor]];
    

    The variable sortedArray contains a sorted version of your original array, and as you can see we pass an array of sort descriptors, this allows you to pass multiple sort descriptors, in case you want to sort basen on the date and another property (e.g. title, name) as a secodnary descriptor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the error Conversion failed when converting date and/or time from character
I'm getting the time via php $current_hour = date(G); Now let's say the $current_hour
I am getting a conversion error every time I try to submit a date
I am getting this datetime format in an xml file: 2012-06-14T11:15:41.587-07:00 2012-06-14T10:49:32.397-07:00 2012-06-11T11:10:49.2-07:00 I
Possible Duplicate: How to Get time difference in iPhone I´m getting date and time
Imagine that you are getting date from different two URLs, one is for map
I'm getting json datetime object as /Date(1346996934000)/ and I'm adviced to convert this date
Is there some clever way of getting the date and time of when the
Basically, I'm getting a date time string from an API, and I want to
I am converting hex-string into a dateformat... I am getting wrong date time with

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.