封裝用於解析NSDate的便利的類

2021-09-23 21:50:02 字數 2975 閱讀 6145

封裝用於解析nsdate的便利的類

此類可以從nsdate中解析出年份,月份,日期,時,分,秒,毫秒,足夠用來做好多事情了,現提供原始碼如下:

以下是核心的類:

timeinfo.h 與 timeinfo.m

//

// timeinfo.h

// showtime

//// created by youxianming on 14-10-16.

//#import @class humantimeinfo;

@inte***ce timeinfo : nsobject

+ (humantimeinfo *)humancanunderstandfromdate:(nsdate *)date;

@end

//

// timeinfo.m

// showtime

//// created by youxianming on 14-10-16.

//#import "timeinfo.h"

#import "humantimeinfo.h"

static nsdateformatter *_dateformatter;

@implementation timeinfo

+ (void)initialize

}+ (humantimeinfo *)humancanunderstandfromdate:(nsdate *)date else

}@end

人類能夠理解的資訊類:

humantimeinfo.h 與 humantimeinfo.m

//

// humantimeinfo.h

// showtime

//// created by youxianming on 14-10-16.

//#import @inte***ce humantimeinfo : nsobject

@property (nonatomic, strong) nsstring *year; // 2014

@property (nonatomic, strong) nsstring *mounth; // 10

@property (nonatomic, strong) nsstring *day; // 16

@property (nonatomic, strong) nsstring *enmounth; // oct

@property (nonatomic, strong) nsstring *fullenmounth; // october

@property (nonatomic, strong) nsstring *hour;

@property (nonatomic, strong) nsstring *min;

@property (nonatomic, strong) nsstring *sec;

@property (nonatomic, strong) nsstring *ampm; // 上午或者下午

@property (nonatomic, strong) nsstring *enweakday;

@property (nonatomic, strong) nsstring *fullweakday;

@property (nonatomic, strong) nsstring *msec; // 毫秒

@end

//

// humantimeinfo.m

// showtime

//// created by youxianming on 14-10-16.

//#import "humantimeinfo.h"

@implementation humantimeinfo

@end

nsdate+currenttime.h 與 nsdate+currenttime.m

//

// nsdate+currenttime.h

// showtime

//// created by youxianming on 14-10-16.

//#import @class humantimeinfo;

@inte***ce nsdate (currenttime)

+ (humantimeinfo *)currenttime;

+ (humantimeinfo *)datefrom:(nsdate *)date;

@end

//

// nsdate+currenttime.m

// showtime

//// created by youxianming on 14-10-16.

//#import "nsdate+currenttime.h"

#import "humantimeinfo.h"

#import "timeinfo.h"

@implementation nsdate (currenttime)

+ (humantimeinfo *)currenttime

+ (humantimeinfo *)datefrom:(nsdate *)date

@end

使用的話,給出nsdate,然後解析出來,就是這麼簡單:)

封裝用於解析NSDate的便利的類

封裝用於解析nsdate的便利的類 此類可以從nsdate中解析出年份,月份,日期,時,分,秒,毫秒,足夠用來做好多事情了,現提供原始碼如下 以下是核心的類 timeinfo.h 與 timeinfo.m showtime created by youxianming on 14 10 16.imp...

資料解析及model的封裝

我們常常需要對資料進行解析,並且建立model存放資料,今天總結一下具體操作以及它們的封裝。1.資料解析並封裝 建立乙個檔案用來進行資料解析。h檔案 import inte ce dataservice nsobject 載入 id loaddatawithlistname nsstring lis...

JSON物件的封裝與解析

一 解析json物件 表結構資訊物件,json格式,名稱為tableobj try 二 封裝json物件 根據表名獲取表結構資訊 param tablename 表名 return 表結構資訊物件 json格式 jsonobject tableinfoobj new jsonobject strin...