1.字符串轉(zhuǎn)13位時(shí)間戳
- (NSString*)getTimeStrWithString:(NSString*)str{?
?? NSDateFormatter *dateFormatter = [[NSDate Formatter alloc] init];// 創(chuàng)建一個(gè)時(shí)間格式化對(duì)象 ?
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//設(shè)定時(shí)間的格式? ??
NSDate*tempDate = [dateFormatter dateFromString:str];//將字符串轉(zhuǎn)換為時(shí)間對(duì)象??
NSString *timeStr = [NSString stringWithFormat:@"%ld", (long)[tempDate ?
timeIntervalSince1970]*1000];//字符串轉(zhuǎn)成時(shí)間戳,精確到毫秒*1000 ? ?
return timeStr;
}
2. ? 13位時(shí)間戳轉(zhuǎn)字符串
- (NSString*)timestampToString:(NSString*)timestamp{
?? NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]/1000];
? ?NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
? ?[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
? ?NSString* string=[dateFormat stringFromDate:confromTimesp];
? ?return ?string;
}
3. ? 判斷字符串是不是純數(shù)字
//過(guò)濾掉數(shù)字 判斷剩下的如果長(zhǎng)度>0 就不是純數(shù)字
- (BOOL)isNum:(NSString*)checkedNumString {
? ? checkedNumString = [checkedNumString ?stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
? ? if(checkedNumString.length>0) {
? ? ? ? returnNO;
? ? }
? ? return YES;
}