I'm using an NSDateFormatter
to format my date in SQLite table cell value.
datetime
, and the values I enter are like: "01.11.2011", "02.11.2012" (dd.MM.yyyy)
When I'm getting the data, I'm using an NSDateFormatter
like this:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@开发者_JS百科"dd.MM.yyyy"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
And my output values are like this:
2011-11-01 00:00:00 +0000
How can I shorten this value as a date value only? Like 2011-11-01
?
01.11.2011
?
Edit: My mistake, I didn't show how I got the values. Like this:
NSDate *myDate = [dateFormatter dateFromString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)]];
Edit-2: I put a breakpoint and checked the coming value from this string, it's like 01.11.2011, as I entered the database.
Your code is pretty much correct. You didn't show how you get the output from the dateFormatter though. With the formatter format set to:
[formatter setDateFormat:@"dd.mm.yyyy"];
NSString *formattedDate = [formatter stringFromDate:[NSDate date]];
This should assign formattedDate with
04.10.2011
精彩评论