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 时间格式的更多相关文章

  1. NSDate时间类/NSDateFormatter日期格式类

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { // NSDate 时间类 继承自N ...

  2. NSDateFormatter 时间格式转换

    NSString *strDate = @“Wed Apr ::”; NSDateFormatter *dateFomatter =[[NSDateFormatter alloc] init]; [d ...

  3. iOSDate时间格式(转)

    在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理.例如: //实例化一个NSDateFormatter对象 NSDateForma ...

  4. iOS开发之时间格式的转化

    在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...

  5. iOS- NSDateFormatter (自定义时间格式)

    一. NSDateFormatter解释 1. 日期(NSDate)是NSString类的格式(stringWithFormat),也可以改变输出,如果需要输出年代信息等则需要进行转换,等等. 2.  ...

  6. iOS - OC NSDate 时间

    前言 NSDate @interface NSDate : NSObject <NSCopying, NSSecureCoding> NSDate 用来表示公历的 GMT 时间(格林威治时 ...

  7. iOS - Swift NSDate 时间

    前言 NSDate public class NSDate : NSObject, NSCopying, NSSecureCoding NSDate 用来表示公历的 GMT 时间(格林威治时间).是独 ...

  8. IOS时间格式转换

    在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...

  9. IOS 时间格式 时间转换 大总结

    //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init]; //设定时间格式,这里 ...

随机推荐

  1. Windows 8/8.1系统下硬盘占用率100%的问题解决思路汇总

    家庭组 2.关闭虚拟内存 3.关闭Windows 8快速开机功能 4.服务进程superfetch 5.系统下软件排除 操作步骤: 1.Windows 8系统的家庭组方便多人不用存储设备就能在局域网中 ...

  2. SQL Server数据库存在判断语句及系统表简介 转

    Transact-SQL Exists Sentences--判断数据库是否存在IF EXISTS(SELECT * FROM master.sysdatabases WHERE name=N'库名' ...

  3. HDU-2552 三足鼎立

    三足鼎立 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  4. JS小知识点----基本包装类型和引用类型

    var s1 = "some text"; s1.color = "red"; alert(s1.color);  //弹出 underfined var s1 ...

  5. HDOJ/HDU 1556 Color the ball(树状数组)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...

  6. 破解安装 SecureCRT 7.0.2 for mac完美破解版,mac secureCRT , apple secureCRT

    mac secureCRT , apple secureCRT 下载地址:http://download.csdn.net/detail/guolichun/7733069 破解安装  SecureC ...

  7. EF-查看生成的SQL语句

    老版本中:EF 4和EF 3.5 SP1 using (var context = new TestDBEntities()) { var query = from p in context.Pare ...

  8. 28个Unix/Linux的命令行神器

    下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具(原文链接),有一些是大家熟悉的,有一些是非常有用的,有一些是不为人知的.这些工具都非常不错,希望每个人都知道 ...

  9. Android Socket编程基础

    前些天写了一个Android手机在局域网内利用Wifi进行文件传输的Demo,其中用到了Socket编程,故此总结(盗了网友的一些图和文字).好久好久没来博客园了~~ 1.什么是Socket? soc ...

  10. JSON和JAVA的POJO的相互转换【转载】

    该类中用用到的jar包:参加文章<使用json-lib进行Java和JSON之间的转换[转载]> import java.util.Collection; import java.util ...