OC/苹果开发 获得时间/时间戳 格式化时间
来源:互联网 发布:百度站长seo 编辑:程序博客网 时间:2024/06/12 18:50
当前时间 :[NSDatedate] 格式 2014-05-21 04:47:37 +0000 (与当前北京时间差8个小时【北京时间:2014-05-21 12:47:37 +0000】)
当前时间戳:[[NSDate date] timeIntervalSince1970] (结果为 NSTimeInterval 格式的长串)
当前时间距离自定义时间间隔:[[NSDate date] timeIntervalSinceDate:某个自定义时间]
/**
格式化时间
timeSeconds 为0时表示当前时间,可以传入你定义的时间戳
timeFormatStr为空返回当当时间戳,不为空返回你写的时间格式(yyyy-MM-dd HH:ii:ss)
setTimeZome ([NSTimeZone systemTimeZone]获得当前时区字符串)
*/
-(NSString *)setTimeInt:(NSTimeInterval)timeSecondssetTimeFormat:(NSString *)timeFormatStrsetTimeZome:(NSString *)timeZoneStr
{
NSString *date_string;
NSDate *time_str;
if( timeSeconds>0){
time_str =[NSDate dateWithTimeIntervalSince1970:timeSeconds];
}else{
time_str=[[NSDate alloc] init];
}
if( timeFormatStr==nil){
date_string =[NSString stringWithFormat:@"%d",(long)[time_str timeIntervalSince1970]];
}else{
NSDateFormatter *date_format_str=[[[NSDateFormatter alloc] init] autorelease];
[date_format_str setDateFormat:timeFormatStr];
if( timeZoneStr!=nil){
[date_format_str setTimeZone:[NSTimeZone timeZoneWithName:timeZoneStr]];
}
date_string =[date_format_str stringFromDate:time_str];
}
return date_string;
}
/**
*用法
*/
-(void)viewWillAppear:(BOOL)animated
{
NSString *a=[self setTimeInt:1317914496setTimeFormat:@"yy.MM.dd HH:mm:ss"setTimeZome:nil];
NSString *b=[self setTimeInt:0setTimeFormat:@"yy.MM.dd HH:mm:ss"setTimeZome:nil];
NSString *c=[self setTimeInt:0setTimeFormat:nil setTimeZome:nil];
NSString *d=[self setTimeInt:0setTimeFormat:@"yy.MM.dd HH:mm:ss"setTimeZome:@"GMT"];
NSLog(@"%@,,,%@,,,%@,,,%@",a,b,c,d);
}
- OC/苹果开发 获得时间/时间戳 格式化时间
- 格式化时间,获得系统时间方法
- OC循环渐进:时间格式化
- java获得当前格式化时间
- 时间,日期格式化以及 格式化时间戳
- 获取时间,格式化时间
- OC中关于时间的几个函数及格式化时间
- OC中关于时间的几个函数及格式化时间
- Java格式化时间戳
- mysql格式化时间戳
- php 格式化时间戳
- js 格式化时间戳
- js格式化时间戳
- JSTL 格式化时间戳
- 时间戳格式化
- JSTL 格式化时间戳
- 时间戳格式化-java
- mysql格式化时间戳
- iOS 发布流程
- HTML相关经验积累总结
- [iOS]ARC下循环引用的问题
- SQL注入原理讲解,很不错!
- UVa - 107 - The Cat in the Hat
- OC/苹果开发 获得时间/时间戳 格式化时间
- SpringMVC的工作原理
- PAT1003 我要通过
- 使用CocoaPods管理第三方开源类库
- 数据库导入
- JS 数据类型转换
- JAVA 修饰符初步
- 64位机器安装autocad和南方cass
- sizeof 与 strlen的区别