NSdate 时间格式
NSdate 时间格式
NSTimeInterval 时间间隔 基本单位 秒
NSDateFormatter 时间格式器 用于日期对象的格式化或字符串解析为日期对象
日期格式如下:
y 年
M 年中的月份
D 当天是今年的第多少天
d 月份中的天数
F 月份中的周数
E 星期几
a Am/pm
H 一天中的小时数(0-23)
k 一天中的小时数(1-24)
K am/pm 中的小时数(0-11) Number 0
h am/pm 中的小时数(1-12) Number 12
m 小时中的分钟数 Number 30
s 分钟中的秒数 Number 55
S 毫秒数 Number 978
z 时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z 时区 RFC 822 time zone -0800
时间戳
时间格式 Nsdate
比较时间
1 比较两个日期是不是同一日期 isEqualToDate;
(2) 获取比较早的时间 earlierDate
3 获取比较晚的时间 laterDate
//初始化一个时间格式
NSDate *curDate =[NSDate date];
把时间格式转化成字符串样式 (但输出的时间比本地时间少8个小时(因为输出的是国际标准时间))
NSLog(@"%@",[NSString stringWithFormat:@“%@“,curDate]);
用NSDateFormatter(时间格式器)转换的时间 是转换成设备时间
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat =@"a h:m:s”;
NSString *times = [formatter stringFromDate:dates];
NSLog(@“%@",times);
如以上代码,如果在下午3点半输出的则输出为:下午 3:30:43(精确到秒)
NSTimeInterval timeinterval =[dates timeIntervalSince1970];
NSString *timestring =[NSString stringWithFormat:@"%d",(int)timeinterval];
NSLog(@“时间戳:%@",timestring);
输出的时间戳是以秒为单位 相当于1970年到现在有多少秒的时间
计算当前时间到时间间隔的日期
获得一天的时间间隔
NSTimeInterval interval = 24 *60*60;(以秒为单位)
获得昨天的日期 当前的时间减去一天的时间(interval)
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-interval];(-为减 +为加)
设置时间格式为 年月日:
famtetter.dateFormat = @“y-M-d”;(自定义的时间输出格式)
系统给的时间输出格式(共有5种样式)
formatter.dateStyle = NSDateFormatterFullStyle;
NSLog(@"%@",[famtetter stringFromDate:yesterday]);
NSdate 时间格式的更多相关文章
- NSDate时间类/NSDateFormatter日期格式类
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { // NSDate 时间类 继承自N ...
- NSDateFormatter 时间格式转换
NSString *strDate = @“Wed Apr ::”; NSDateFormatter *dateFomatter =[[NSDateFormatter alloc] init]; [d ...
- iOSDate时间格式(转)
在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理.例如: //实例化一个NSDateFormatter对象 NSDateForma ...
- iOS开发之时间格式的转化
在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...
- iOS- NSDateFormatter (自定义时间格式)
一. NSDateFormatter解释 1. 日期(NSDate)是NSString类的格式(stringWithFormat),也可以改变输出,如果需要输出年代信息等则需要进行转换,等等. 2. ...
- iOS - OC NSDate 时间
前言 NSDate @interface NSDate : NSObject <NSCopying, NSSecureCoding> NSDate 用来表示公历的 GMT 时间(格林威治时 ...
- iOS - Swift NSDate 时间
前言 NSDate public class NSDate : NSObject, NSCopying, NSSecureCoding NSDate 用来表示公历的 GMT 时间(格林威治时间).是独 ...
- IOS时间格式转换
在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...
- IOS 时间格式 时间转换 大总结
//实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init]; //设定时间格式,这里 ...
随机推荐
- DevExpress控件学习总结 z
1.Navigation & Layout 1.1 Bar Manager 如果想在窗体或用户控件(user control)上添加工具条(bars)或弹出菜单(popup menus),我们 ...
- strncpy 用法
strncpy 用法 原型:extern char *strncpy(char *dest, char *src, int n); 用法:#include <string.h> 功能: ...
- ReentrantLock Condition 实现消费者生产者问题
import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.ExecutorService; im ...
- js的 new image()用法[转]
创建一个Image对象:var a=new Image(); 定义Image对象的src: a.src=”xxx.gif”; 这样做就相当于给浏览器缓存了一张图片. 图像对象: 建立图像对 ...
- 关于ASSERT(断言)的作用
程序一般分为Debug 版本和Release 版本,Debug 版本用于内部调试,Release 版本发行给用户使用.断言assert 是仅在Debug 版本起作用的宏,它用于检查“不应该”发生的情况 ...
- nyoj 119 士兵杀敌(三)【线段树区间最大值最小值差】
士兵杀敌(三) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进 ...
- Eclipse修改字体大小
1.MyEclipse|Window|General|Appearance|Colors and Fonts->点击Text Font->Edit
- Visual Studio 2015安装过程卡住,解决办法
Visual Studio 2015安装过程中卡住的情况有很多,我遇到的是卡在安装windows 更新KB2999226,解决办法 手动安装此更新包,位置在Visual Studio的安装包中,目录: ...
- springboot +spring security4 自定义手机号码+短信验证码登录
spring security 默认登录方式都是用户名+密码登录,项目中使用手机+ 短信验证码登录, 没办法,只能实现修改: 需要修改的地方: 1 .自定义 AuthenticationProvide ...
- 【硬件】DELLserver硬件监控及DELL系统管理工具OMSA介绍
1.1.1. DELLserver硬件监控及DELL系统管理工具OMSA介绍 本文介绍採用使用Nagios和OMSA监控DELLserver的硬件健康状态,Nagios监控的方式是NRPE模式,须要配 ...