Skip to content

Commit 70c14ef

Browse files
author
li6185377
committed
add date to string using model dateFormatte
1 parent ea3a4d5 commit 70c14ef

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

LKDBHelper/Helper/LKDBHelper.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ -(void)sqlString:(NSMutableString*)sql AddOder:(NSString*)orderby offset:(int)of
542542
{
543543
[sql appendFormat:@" limit %d offset %d",count,offset];
544544
}
545+
else if(offset > 0)
546+
{
547+
[sql appendFormat:@" limit %d offset %d",INT_MAX,offset];
548+
}
545549
}
546550
- (NSMutableArray *)executeOneColumnResult:(FMResultSet *)set
547551
{

LKDBHelper/Helper/LKDBUtils.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ @interface LKDateFormatter : NSDateFormatter
1313
@end
1414

1515
@implementation LKDateFormatter
16+
- (id)init
17+
{
18+
self = [super init];
19+
if (self) {
20+
self.lock = [[NSLock alloc]init];
21+
self.generatesCalendarDates = YES;
22+
self.dateStyle = NSDateFormatterNoStyle;
23+
self.timeStyle = NSDateFormatterNoStyle;
24+
}
25+
return self;
26+
}
1627
//防止在IOS5下 多线程 格式化时间时 崩溃
1728
-(NSDate *)dateFromString:(NSString *)string
1829
{
@@ -98,6 +109,9 @@ +(NSString*)stringWithDate:(NSDate*)date
98109
{
99110
NSDateFormatter* formatter = [self getDBDateFormat];
100111
NSString* datestr = [formatter stringFromDate:date];
112+
if(datestr.length > 19){
113+
datestr = [datestr substringToIndex:19];
114+
}
101115
return datestr;
102116
}
103117
+(NSDate *)dateWithString:(NSString *)str

LKDBHelper/Helper/NSObject+LKModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
*/
6767
-(void)userSetValueForModel:(LKDBProperty*)property value:(id)value;
6868

69-
69+
+(NSDateFormatter*)getModelDateFormatter;
7070
//lkdbhelper use
7171
-(id)modelGetValue:(LKDBProperty*)property;
7272
-(void)modelSetValue:(LKDBProperty*)property value:(id)value;

LKDBHelper/Helper/NSObject+LKModel.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ +(NSDictionary *)getTableMapping
6565
return nil;
6666
}
6767
#pragma mark- Table Data Function 表数据
68+
+(NSDateFormatter*)getModelDateFormatter{
69+
return nil;
70+
}
6871
-(id)modelGetValue:(LKDBProperty *)property
6972
{
7073
id value = [self valueForKey:property.propertyName];
@@ -83,7 +86,13 @@ -(id)modelGetValue:(LKDBProperty *)property
8386
}
8487
else if([value isKindOfClass:[NSDate class]])
8588
{
86-
returnValue = [LKDBUtils stringWithDate:value];
89+
NSDateFormatter* formatter = [self.class getModelDateFormatter];
90+
if(formatter){
91+
returnValue = [formatter stringFromDate:value];
92+
}
93+
else{
94+
returnValue = [LKDBUtils stringWithDate:value];
95+
}
8796
}
8897
else if([value isKindOfClass:[UIColor class]])
8998
{

0 commit comments

Comments
 (0)