iOS开发时间戳与时间,时区的转换,汉字与UTF8,16进制的转换
来源:互联网 发布:淘宝游戏充值赚钱吗 编辑:程序博客网 时间:2024/05/18 21:06
iOS开发时间戳与时间,时区的转换,汉字与UTF8,16进制的转换
(2013-07-19 15:56:13)转载▼
标签:
ios时间戳
ios开发时间戳
ios16进制转中文
ios开发utf8转中文
ios汉字转utf8和16进
//获取当前系统的时间戳
+(long)getTimeSp{
long time;
NSDate *fromdate=[NSDate date];
time=(long)[fromdate timeIntervalSince1970];
return time;
}
//将时间戳转换成NSDate
+(NSDate *)changeSpToTime:(NSString*)spString{
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString intValue]];
return confromTimesp;
}
//将时间戳转换成NSDate,加上时区偏移
+(NSDate*)zoneChange:(NSString*)spString{
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString intValue]];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:confromTimesp];
NSDate *localeDate = [confromTimesp dateByAddingTimeInterval: interval];
return localeDate;
}
//比较给定NSDate与当前时间的时间差,返回相差的秒数
+(long)timeDifference:(NSDate *)date{
NSDate *localeDate = [NSDate date];
long difference =fabs([localeDate timeIntervalSinceDate:date]);
return difference;
}
//将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
+(NSString*)nsdateToString:(NSDate *)date{
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* string=[dateFormat stringFromDate:date];
return string;
}
//将yyyy-MM-dd HH:mm:ss格式时间转换成时间戳
+(long)changeTimeToTimeSp:(NSString *)timeStr{
long time;
NSDateFormatter *format=[[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *fromdate=[format dateFromString:timeStr];
time= (long)[fromdate timeIntervalSince1970];
[format release];
return time;
}
//获取当前系统的yyyy-MM-dd HH:mm:ss格式时间
+(NSString *)getTime{
NSDate *fromdate=[NSDate date];
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* string=[dateFormat stringFromDate:fromdate];
return string;
}
点击下载DEMOhttp://www.kuaipan.cn/file/id_30491149655345667.htm 访问密码:At7uJx
//发送数据时,16进制数->Byte数组->NSData,加上校验码部分
+(NSData *)hexToByteToNSData:(NSString *)str{
int j=0;
Byte bytes[[str length]/2];
for(int i=0;i<[str length];i++)
{
int int_ch; ///两位16进制数转化后的10进制数
unichar hex_char1 = [str characterAtIndex:i]; ////两位16进制数中的第一位(高位*16)
int int_ch1;
if(hex_char1 >= '0' && hex_char1 <='9')
int_ch1 = (hex_char1-48)*16; //// 0 的Ascll - 48
else if(hex_char1 >= 'A' && hex_char1 <='F')
int_ch1 = (hex_char1-55)*16; //// A 的Ascll - 65
else
int_ch1 = (hex_char1-87)*16; //// a 的Ascll - 97
i++;
unichar hex_char2 = [str characterAtIndex:i]; ///两位16进制数中的第二位(低位)
int int_ch2;
if(hex_char2 >= '0' && hex_char2 <='9')
int_ch2 = (hex_char2-48); //// 0 的Ascll - 48
else if(hex_char2 >= 'A' && hex_char2 <='F')
int_ch2 = hex_char2-55; //// A 的Ascll - 65
else
+(long)getTimeSp{
}
//将时间戳转换成NSDate
+(NSDate *)changeSpToTime:(NSString*)spString{
}
//将时间戳转换成NSDate,加上时区偏移
+(NSDate*)zoneChange:(NSString*)spString{
}
//比较给定NSDate与当前时间的时间差,返回相差的秒数
+(long)timeDifference:(NSDate *)date{
}
//将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
+(NSString*)nsdateToString:(NSDate *)date{
}
//将yyyy-MM-dd HH:mm:ss格式时间转换成时间戳
+(long)changeTimeToTimeSp:(NSString *)timeStr{
}
//获取当前系统的yyyy-MM-dd HH:mm:ss格式时间
+(NSString *)getTime{
}
点击下载DEMOhttp://www.kuaipan.cn/file/id_30491149655345667.htm 访问密码:At7uJx
//发送数据时,16进制数->Byte数组->NSData,加上校验码部分
+(NSData *)hexToByteToNSData:(NSString *)str{