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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:46:42+00:00 2026-05-25T00:46:42+00:00

Problem I have a timestamp that I am converting to an NSDate . Now

  • 0

Problem

I have a timestamp that I am converting to an NSDate. Now I need to extract the time. I have successfully extracted the time but the only problem I have is that if the minutes are 0, it displays “0” instead of “00”. So 11:00 would be shown as: “11:0”. Everything else works, for example 11:30 works fine.

Code

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[self.program.sd intValue]];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm"];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:(kCFCalendarUnitHour | kCFCalendarUnitMinute) fromDate:date];
    NSInteger hour = [components hour];
    NSInteger minute = [components minute];
    NSLog(@"%d:%d", hour, minute);

Any suggestions? What have I done wrong? Is there a better way to extract both the hour and the minute at the same time rather than what I’ve done above?

Thanks!

  • 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-25T00:46:43+00:00Added an answer on May 25, 2026 at 12:46 am

    Are you getting the right values back? If all you’re doing is displaying the time to the user, you should use NSDateFormatter to create a string from the date object.

    NSDateFormatter *formatter = [[NSDateFormatter new] autorelease];
    [formatter setDateFormat:@"hh:mm"];
    NSString *timeString = [formatter stringFromDate:date];
    

    Possibilities for format strings are documented in UTS #35: Locale Data Markup Language Appendix F: Date Format Patterns.

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

Sidebar

Related Questions

Problem I have timestamped data, which I need to search based on the timestamp
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: I have a database of sensor readings with a timestamp for the time
I have a problem in converting the Unix timestamp to sql server timestamp. I
I have a problem converting a timestamp in javascript. I have this timestamp: 2011-10-26T12:00:00-04:00
Problem: We have a web app that calls some web services asynchronously (from the
Problem: I have to support users who need to edit web pages. Some of
Problem: I have a python script that I have running as a service. It's
Problem : I have a hand held device that scans those graphic color barcodes
Problem I have a custom tab control using Chrome-shaped tabs that binds to a

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.