0

Q1. NSDate *now = [NSDate date];
NSLog(@"Current date:%@",now);

The time shown is 4 hours ahead of the system time. I am wondering why is it so and how can I correct it?

Q2.. In C/C++, strings are treated as an array of characters. Is it the case in Objective-C also?

Rutvij Kotecha
  • 935
  • 2
  • 10
  • 21
  • You need to look into how `NSDate` handles time zones. See here: http://stackoverflow.com/questions/1268509/convert-utc-nsdate-to-local-timezone-objective-c – sudo rm -rf Jul 29 '12 at 03:07

2 Answers2

3
NSDate *now = [NSDate date];
NSLog(@"Current date:%@",now); 

it's "now" not "date".

skytz
  • 2,201
  • 2
  • 18
  • 23
1

A1: NSLog(@"%@", now) is effectively the same as NSLog(@"%@", [now description]). The NSDate object doesn't care what the timezone is, so its description method will just give you the time in UTC. If you need to format with the right timezone and locale, you'll need to use an NSDateFormatter object to convert it to a nicely formatted string first.

A2: Yes and no, but mostly no. You can do this:

char *cString = "I am a C string";

to create a C string, which you can treat exactly as you would in C. That's something you very rarely see in Objective-C, though, except when it's absolutely necessary. The "normal" way to use strings is with instances of NSString or NSMutableString, which are fully-fledged objects:

NSString *normalString = @"I'm above all that."; (note the @ symbol)

Siobhán
  • 1,451
  • 10
  • 9