获取时间戳
来源:互联网 发布:淘宝权重怎么查 编辑:程序博客网 时间:2024/06/06 07:45
1:上报数据需要上报时间戳;
// NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
// NSString *timestamp = [NSString stringWithFormat:@"%.0f", interval];//转为字符型,浮点型去掉后面的六位,便于后台需要
// NSLog(@"time-->%@",timestamp);
[
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;//获取毫秒时间戳
]2:显示时间间隔http://blog.csdn.net/deft_mkjing/article/details/51507497
// 这里进行一次分析
1.首先根据传进来的formatString做一个格式对象出来,nil的话就默认为yyyy-MM-dd HH:mm:ss
2.NSTimerInterval timeInterval = [当前时间 timeIntervalSinceDate:发布时间];
3.当前时间获取
NSDate *当前时间 = [NSDate date] //!<这里获取的是当前时间对象,格林尼治的
NSString *当前时间字符串 = [格式对象 stringFromDate:] //!<先转换成字符串进行一次中间变换
NSDate *最终的当前时间对象 = [格式对象 dateFromString:当前时间字符串];//!<这个时候字符串就变成了当地时区的时间对象了,完美!!
4.获取传进来时间的对象 发布时间类似于微博发布的一个时间点 //!<根据指定的timeIntervale来获取对象
NSDate *发布时间 = [NSDate dateWithTimeIntervalSince1970:(这里把传入的字符串转换成浮点型)]
5.算出来之后就是一个NSTimeInterval,然后根据判断获取到具体的字符串返回
代码如下:
+(NSString *)internalFromCreatTime:(NSString *)creatTimeString formatString:(NSString *)formatString
{
//创建对应的格式
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:formatString?formatString:@"yyyy-MM-dd HH:mm:ss"];
//生成对应的格式日期对象
NSDate *currentDate=[dateFormatter dateFromString:[dateFormatter stringFromDate:[NSDate new]]];
NSDate *nd = [NSDate dateWithTimeIntervalSince1970:creatTimeString.floatValue];
//计算日期间隔
NSTimeInterval timeInterval= [currentDate timeIntervalSinceDate:nd];
float days = timeInterval / (3600.0*24);
float hours=timeInterval /3600.0;
float minutes = timeInterval / 60;
if (days >7)
{
return [dateFormatter stringFromDate:nd];
}
else if (days>=1)
{
return [NSString stringWithFormat:@"%d天前",(int)days];
}
else if (hours>=1)
{
return [NSString stringWithFormat:@"%d小时前",(int)hours];
}
else
{
return [NSString stringWithFormat:@"%d分钟前",(int)minutes];
}
}
- 获取当前时间 时间戳
- JavaScript 获取时间,时间戳
- 获取指定时间时间戳
- JAVA获取时间戳
- C# 获取时间戳
- c# 获取时间戳
- c++ 获取时间戳
- 获取时间戳
- js获取时间戳
- c# 获取时间戳
- Python 获取时间戳
- JS 获取时间戳
- 获取linux时间戳
- PHP获取时间戳
- iOS获取时间戳
- boost获取时间戳
- C#获取时间戳
- 获取时间戳
- android自定义抽奖转盘
- xcode7免证书真机调试
- spring security 4.1 中自定义登录界面和扩展login controller
- POJ 2778 DNA Sequence(AC自动机+矩阵加速)
- Xcode编译之后使用cocoapods导入的第三库中头文件找不到库中的某些文件
- 获取时间戳
- Android RecyclerView 使用完全解析 体验艺术般的控件
- QWindowsWindow::setGeometryDp: Unable to set geometry
- ROS 学习系列 -- RViz 实时观测机器人建立导航2D封闭空间地图过程 (SLAM)
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- js 文件的上传 分段读取文件 FileReader
- [392]Is Subsequence
- jQuery attr()获取属性和设置属性的方法
- Boost C++ 库入门