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

  • Home
  • SEARCH
  • 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 6014679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:43:40+00:00 2026-05-23T02:43:40+00:00

NSLog(@%@ – %@ – %@,currTime,sunrise,sunset); NSString *curtime = [[currTime substringToIndex:(currTime.length-4)] stringByAppendingString:@-0000]; NSDateFormatter *formatter1 =

  • 0
NSLog(@"%@ - %@ - %@",currTime,sunrise,sunset);
NSString *curtime = [[currTime substringToIndex:(currTime.length-4)] stringByAppendingString:@"-0000"];
NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init];
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]autorelease];
[formatter1 setDateFormat:@"EEE, dd MMM yyyy h:mm aZ"];
[formatter1 setLocale:locale];

NSDate *time = [formatter1 dateFromString:curtime];
[formatter1 setDateFormat:@"EEE dd MMM yyyy"];
NSString *zone = [formatter1 stringFromDate:time];
NSString *r = [sunrise stringByAppendingString:zone];
NSString *s = [sunset stringByAppendingString:zone];

[formatter1 setDateFormat:@"hh:mm aEEE dd MMM yyyy"];
NSDate *rise = [formatter1 dateFromString:r];
NSDate *set = [formatter1 dateFromString:s];

unsigned int flags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components1 = [calendar components:flags fromDate:rise];
NSDateComponents *components2 = [calendar components:flags fromDate:set];
NSDateComponents *components3 = [calendar components:flags fromDate:time];

NSInteger riseHour = [components1 hour];
NSInteger setHour = [components2 hour];
NSInteger timeHour = [components3 hour];

NSLog(@"\nSunrise: %@ \nSunset: %@ \nCurrent: %@",rise,set,time);
NSLog(@"Rise: %i  Set: %i  Time: %i",riseHour,setHour,timeHour);

I’d expect this to work. However, look at the output below:

Sun, 12 Jun 2011 1:54 am CDT – 6:33 am – 8:34 pm

Sunrise: 2011-06-11 21:33:00 +0000

Sunset: 2011-06-12 11:34:00 +0000

Current: 2011-06-12 01:54:00 +0000

Rise: 6 < correct

Set: 20 < correct

Time: 10 < wrong

  • 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-23T02:43:41+00:00Added an answer on May 23, 2026 at 2:43 am

    Try setting the timezone to GMT-0 on both the formatter and the calendar. You might be pleasantly surprised.

    [NSTimeZone timeZoneForSecondsFromGMT:0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSLog(@Status: %@, [[[xmlElement elementsForName:@status] objectAtIndex:0] stringValue]); NSString *val = [[[xmlElement elementsForName:@status] objectAtIndex:0] stringValue]; NSLog(@Status:
NSLog(@Status: %@, [[[xmlElement elementsForName:@status] objectAtIndex:0] stringValue]); NSString *val = [[[xmlElement elementsForName:@status] objectAtIndex:0] stringValue]; if
My code is: NSLog(@saving jpeg); NSString *jpegFilePath = [NSString stringWithFormat:@%@/%@.jpeg,docDir, [self.Youtubearray objectAtIndex:0]]; NSData *data2
I want to take an NSLog() message and save it as a NSString. For
Test case: NSLog(@%f, M_PI); NSLog(@%@, [NSString stringWithFormat:@%f, M_PI]); NSLog(@%@, [NSNumber numberWithDouble:M_PI]); Results: 3.141593 3.141593
The following code works as expected: NSLog(@%@, [NSString stringWithString:@test]; // Logs test But when
NSLog puts something into stderr, is there a Objective-c method that can put NSString
NSLog(@testString: %@, testString); P.S. the second testString is a pointer to a NSString. I
Hi there I have this code NSLog(@%@,URLRequestQueryString); NSString *sendToServerString = [NSString stringWithFormat:@http://mydomain.co.uk/req.php%@,URLRequestQueryString]; NSURL *sendToServer
I use NSLog in my application. And I'd like to get rid of the

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.