Reputation: 4295
I am trying to change format of a date in objective c. I have a NSDate
in the following format..
2012.03.14 AD at 03:22:13 PDT
This code working fine.
NSDateFormatter* df_utc = [[[NSDateFormatter alloc] init] autorelease];
[df_utc setTimeZone:[NSTimeZone timeZoneWithName:@"PST"]];
[df_utc setDateFormat:@"yyyy.MM.dd G 'at' HH:mm:ss zzz"];
i want to convert to
03/14/2012 5:12:38 IST
this format.. I tried something like this
NSDateFormatter* df_utc = [[[NSDateFormatter alloc] init] autorelease];
[df_utc setTimeZone:[NSTimeZone timeZoneWithName:@"PST"]];
[df_utc setDateFormat:@"MM/dd/yyyy h:mm:ss z"];
[df_utc stringFromDate:[NSDate date]];
But it's returning NULL
values, Anyone help me to figure out.
Thanks in Advance
Upvotes: 0
Views: 824
Reputation: 9977
So in your actual code, you probably don't use [NSDate date]
to create the date, but another data? Have you checked, that your date is NOT nil
, when putting it into the formatter? Have you tried if your formatter is working just with [NSDate date]
? Also your zone
variable could be the problem. Is it filled correctly?
Is this your actual code? If not pls show us. And you can always use the debuger, to check line by line, if some variables are nil
or not the value, you expected.
Upvotes: 2