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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:03:18+00:00 2026-05-12T11:03:18+00:00

In the docs, Apple gives an example on how to add some hours and

  • 0

In the docs, Apple gives an example on how to add some hours and minutes to an existing date:

NSDate *today = [NSDate date];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setHour:1];
[offsetComponents setMinutes:30];
NSDate *endOfWorldWar3 = [gregorian dateByAddingComponents:comps toDate:today options:0];

But now, I have date which is printed out in 12h format with AM / PM (unicode standard format specifier is “a”).

So I have an date object which is set to 8:00 ‘o clock, and now I want to switch that to PM or 20:00 ‘o clock. Hard to explain. NSDateComponents doesn’t have a component for that.

The docs say that all these NSDateComponents things like hour, minute, day, etc. are in context with a calendar object. Makes sense. But I haven’t found anything in NSCalender which would say “this is 12h format” or “this is 24h format”.

So actually, what happens when I change the hour period? Isn’t that actually just simple math to say “lets take 12 hours off, or lets add 12 hours”? Any idea?

  • 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-12T11:03:18+00:00Added an answer on May 12, 2026 at 11:03 am

    NSDate is just a value for a moment in time. How you display it, whether it has PM or is in the 24 hour format, is in the formatting.

    Here are some formatters:

    k gives you 24-hour hours
    a gives you AM/PM
    

    From here.

    Use the info on that page with NSDateFormatter, like this:

    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"yyyy-MM-dd 'at' kk:mm"];
    
    NSDate *formatterDate = [inputFormatter dateFromString:@"1999-07-11 at 22:30:03"];
    
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
    [outputFormatter setDateFormat:@"kk:mm 'on' EEEE MMMM d"];
    
    NSString *newDateString = [outputFormatter stringFromDate:formatterDate];
    
    NSLog(@"newDateString %@", newDateString);
    // For US English, the output is:
    // newDateString 22:30 on Sunday July 11
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just added some code that was taken from the Apple docs which shows
In the Apple Docs, they say that NSDateFormatter uses the Unicode for spec. I've
In the apple docs it states The portion is the optional string @2x and
From reading the Apple Docs on Core Data, I've learned that you should not
I have created a UITableViewCell using UITableViewCellStyleValue1, which the Apple docs define as: A
In docs link about expires # Task expires after one minute from now. add.apply_async(args=[10,
In the Apple docs it says that JavaScript execution time is limited to 10
In the apple docs it states that nsapplication is the file owner of the
According to the Apple docs, MKPinAnnotationView's pin color is available in red, green and
When I look at apple docs, I get a bit confused. On one hand

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.