With the following code, foo gives me the local time or GMT?
NSString * foo = [formatter2 stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-2 * 3600]];
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The string
flyeridwill represent the time minus 2 hours in your current time zone, yes. That’s the purpose of the date formatter, which, by default, uses the computer’s Locale information to convert a passed-in date to the representation closest to what the user expects. That includes using the computer’s time zone. (You can change that, of course, by sendingsetTimeZone:to the formatter.)The date object itself has no time zone. It is only a moment in time, whose description or representation varies depending on where on the globe you are. For example, the moment when John Lennon was pronounced dead is represented in its local time (GMT-5) as 8 December, 1980, 11:15 AM, but over on the West coast of the US, that’s 8:15 AM, and in Lennon’s place of birth, it’s 4:15 in the afternoon. He was only pronounced dead once, though — same moment, different ways of reading it.