要在iOS7中解析的JSON的日期格式
我想在iOS中解析以下JSON响应:要在iOS7中解析的JSON的日期格式,ios,json,date,ios7,date-format,Ios,Json,Date,Ios7,Date Format,我想在iOS中解析以下JSON响应: "myCaldDate": 1392076800000 这个日期格式叫什么?我们如何在iOS应用程序中解析和显示dd-mm-yyyy格式,并将日期同步到设备日历 谢谢 -(NSDate)dateDiff:(double )myCaldDate { / Date difference for the purpose of showing games listes double timeInterval = myCaldDate/1000.0f
"myCaldDate": 1392076800000
这个日期格式叫什么?我们如何在iOS应用程序中解析和显示dd-mm-yyyy
格式,并将日期同步到设备日历
谢谢
-(NSDate)dateDiff:(double )myCaldDate
{
/ Date difference for the purpose of showing games listes
double timeInterval = myCaldDate/1000.0f;
NSDate *convertedDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
return convertedDate;
}
现在同步:-
-(NSString *)syncWithCalender:(NSDate *)convertDate
{
NSDate *todayDate = [NSDate date];
double ti = [convertDate timeIntervalSinceDate:todayDate];
ti = ti * -1;
if(ti <= 1)
{
return @"Just Now";
}
else if (ti < 60)
{
return @"less than a minute ago";
}
else if (ti < 3600)
{
int diff = (ti / 60);
if (diff==1)
{
return [NSString stringWithFormat:@"%d minute ago", diff];
}
return [NSString stringWithFormat:@"%d minutes ago", diff];
}
else if (ti < 86400)
{
int diff = (ti / 60 / 60);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d hour ago", diff];
}
return[NSString stringWithFormat:@"%d hours ago", diff];
}
else if (ti < 2629743)
{
int diff = (ti / 60 / 60 / 24);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d day ago", diff];
}
return[NSString stringWithFormat:@"%d days ago", diff];
}
else if (ti < 31557600)
{
int diff = (ti / 60 / 60 / 24 / 30);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d month ago", diff];
}
return[NSString stringWithFormat:@"%d months ago", diff];
}
else
{
int diff = (ti / 60 / 60 / 24 / 30 / 12);
if (diff == 1)
{
return[NSString stringWithFormat:@"%d year ago", diff];
}
return[NSString stringWithFormat:@"%d years ago", diff];
}
}
-(NSString*)与日历同步:(NSDate*)转换日期
{
NSDate*今天日期=[NSDate日期];
双ti=[convertDate-TimeIntervalsCenceDate:todayDate];
ti=ti*-1;
if(ti这似乎是Crowder所说的UNIX日期或纪元的时间间隔。
要从中创建字符串日期,您应该:
从该时间间隔创建NSDate对象
创建并设置NSDateFormatter对象
从日期格式化程序创建字符串
代码:
NSDate * date = [[NSDate alloc] initWithTimeIntervalSince1970:interval];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
//you can choose dofferetnt styles or create your own by using a format string conforms to uni specifications
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
dateFormatter.timeStyle = NSDateFormatterNoStyle;
NSString * string = [dateFormatter stringFromDate:date];
-initWithTimeIntervalSince1970:返回一个NSDate对象,该对象设置为从1970年1月1日格林尼治标准时间的第一个瞬间开始的给定秒数
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)秒参数秒从参考日期算起的秒数,1
1970年1月,GMT,新日期。使用否定参数
指定此日期之前的日期。返回NSDate对象设置为的值
从参考日期算起的秒数
讨论此方法对于从中创建NSDate对象非常有用
BSD系统函数返回的时间值
不知道它是否有特定的名称,看起来像是从历元值开始的毫秒,假设该日期表示2014年2月11日格林威治标准时间午夜(历元为1970年1月1日格林威治标准时间午夜).每当你看到的只是一个数字,而且是一个日期,很可能是从纪元开始的秒数或从纪元开始的毫秒数。这是一个时间戳值吗?如果是,你可以检查
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[@"1392076800000" doubleValue]/1000];
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"LLL dd yyyy, hh:mm a"];
NSString *strdate=[formatter stringFromDate:date];
NSLog(@"%@",strdate);