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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:25:29+00:00 2026-05-24T18:25:29+00:00

I tested those calls : NSLog(@%@, [NSDate date]); NSLog(@%@, [NSDate convertToUTC:[NSDate date]]); NSLog(@%@, [[NSDate

  • 0

I tested those calls :

    NSLog(@"%@", [NSDate date]);
    NSLog(@"%@", [NSDate convertToUTC:[NSDate date]]);
    NSLog(@"%@", [[NSDate date] stringValueWithFormat:@"yyyyMMddHHmmss"]);
    NSLog(@"%@", [[NSDate convertToUTC:[NSDate date]] stringValueWithFormat:@"yyyyMMddHHmmss"]);

+ (NSDate*) convertToUTC:(NSDate*)sourceDate {
    [NSTimeZone resetSystemTimeZone];
    NSTimeZone* currentTimeZone = [NSTimeZone localTimeZone];
    NSTimeZone* utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];

    NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:sourceDate];
    NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:sourceDate];
    NSTimeInterval gmtInterval = gmtOffset - currentGMTOffset;

    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:sourceDate] autorelease];     
    return destinationDate;
}
- (NSString*) stringValueWithFormat:(NSString*)formatRetour {
    NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:formatRetour];

    return [dateFormatter stringFromDate:self];
}

They give me :

2011-08-17 13:03:58 +0000
2011-08-17 11:03:58 +0000
20110817150358
20110817130358

On my phone, all configured to France/French, it’s now : 15:03:58.

I don’t understand the conversions that are done here.

1 gives me the real time at GMT
2 gives me something I don’t understand…
3 gives the real time on the phone
4 gives the real time at GMT

I’m lost… From where does 2 comes ? How does those calls work ?
I mean, [NSDate date] gives 13:03 whith a +0000 timezone. Why formatting it shows 15:03 ?
Why 1 and 2 show a +0000 timezone, but different times ?

Could you guide me through this ?

  • 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-24T18:25:30+00:00Added an answer on May 24, 2026 at 6:25 pm

    NSLog will always print the description of the date object with a +0000 timezone.

    When you use a NSDateFormatter to get a string from your date, it will use the timezone of your phone. With "yyyyMMddHHmmssZZZ" you would have got 20110817150358+0200.

    It’s the same thing for the date you convert to UTC: you get 11:03 for GMT+0 (NSLog) which is the same as 13:03+0200 (using NSDateFormatter).

    Yet convertToUTC: is buggy since the value should be 13:03+0000.

    NSDate to NSDate conversion methods don’t make sense. NSDate holds an absolute time and does not care about timezones. You only have to take timezones into account when doing NSString from/to NSDate conversions.

    That’s why when you “convertToUTC” 15:03+0200 you get 13:03+0200 which is the same as 11:03+0000.

    A method like - (NSString *)UTCRepresentation would make sense though.

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

Sidebar

Related Questions

I tested the following code in firefox scratchpad and got interesting result? var date=new
Has anyone ever tested, or does anyone know, the performance differences of these two
Tested app in Instrumens for memory leak getting multiple leaks for using multiple times
I tested out the script below in jsfiddle and it works fine, can someone
I tested this on both .Net 4.0 and .Net 4.0 CP, same result. This
I tested the behavior of copy constructor with functions that return an object by
I tested: rm \-\-remove-files but I am unable to remove it. How can I
i tested HttpResponse#flushBuffer and PrintWriter#flush on Tomcat 7 below, but it seemed that the
I tested each statement on its own and it works, but when I use
I have tested out hundreds of different codes, either they work and screw something

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.