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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:45:56+00:00 2026-06-17T23:45:56+00:00

Possible Duplicate: Getting date from [NSDate date] off by a few hours NSDate date

  • 0

Possible Duplicate:
Getting date from [NSDate date] off by a few hours
NSDate date don’t give me the right hour

I have this piece of code:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];

NSString *formattedDateInString = [formatter stringFromDate:[self.datePicker date]];
NSLog(@"This is the formatted date (STRING) ---> %@" ,formattedDateInString);
self.fromHourLabel.text = formattedDateInString;

NSDate *date = [formatter dateFromString:formattedDateInString];
NSLog(@"This is the date (NSDate) ---> %@" ,date);
self.fromHour = date;

I basically get the date from a UIDatePicker, set Hours and Minutes as a label text and save the date into a property called fromHour. In the -viewDidLoad method I also have:

self.datePicker.timeZone = [NSTimeZone localTimeZone];

This is the output:

enter image description here

as you can see, with this code, I have two main problems:

  • The first output say 17.30 and the second 16:30 (the first output is correct, the second is wrong) why?
  • The second output is formatted with “yyyy-MM-dd HH:mm:ss” but I need only “HH:mm”.

Can you help me?

  • 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-17T23:45:57+00:00Added an answer on June 17, 2026 at 11:45 pm

    I know there are dozens of existing questions that cover this but I can’t find one.

    The problem is simple. When you print an object using NSLog or a string format containing the %@ format specifier, the description method is called on the object.

    The description method of NSDate always displays the full date using the Zulu timezone (+0000).

    If you want a date printed in a specific format then use NSDateFormatter to convert to a string and print the string.

    Edit: Based on info from the comments, part of the problem here is that you start with the proper NSDate. You then convert that to a string with the format HH:mm. You then create a new NSDate from that string. The better solution is to simply save the original date and avoid the creation of the 2nd date.

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

Sidebar

Related Questions

Possible Duplicate: Getting Index of an Object from NSArray? I have one Array and
Possible Duplicate: Format Date in Javascript I have this date: var newDate = /Date(1333609200000)/;
Possible Duplicate: Getting time and date from timestamp with php I am trying to
Possible Duplicate: Getting unix timestamp from Date() I am having the date Fri, 09
Possible Duplicate: Getting specific days in a month I've touched on this problem once
Possible Duplicate: Getting Filename from file descriptor in C Obtain filename from file pointer
Possible Duplicate: Getting a FILE* from a std::fstream Is there a way to obtain
Possible Duplicate: Getting the timestamp from last saturday (every week)? If today is Sunday,
Possible Duplicate: How to Get time difference in iPhone I´m getting date and time
Possible Duplicate: Why I’m getting StackOverflowError I am using two classes: Date and Exam.

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.