80.iOS yyyy年份与YYYY的区别 NSDate 时间差一年 时间多出一年

yyyy年份与YYYY的区别

It uses yyyy to specify the year component. A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year.
年份如果用大Y会是这周的年份,小y才是标准的年份
例如2013年12月29号开始,如果用大Y的话就是2014年的第一周了,年份会转成2014

NSDate *currentDateTime = [NSDatedate];

    NSDateFormatter *fomatter = [[NSDateFormatteralloc]init];

    [fomatter setDateFormat:@"yyyy-MM-dd HH:mm"];

    NSString *curentDateStr = [fomatterstringFromDate:currentDateTime];

//这两份代码在大部分时间是没有区别的  但如果当前时间是例如:20151229这样的日期 则第一份代码取出来的日期是20151229 第二份成了20161229  差别一年

NSDate *currentDateTime = [NSDatedate];

    NSDateFormatter *fomatter = [[NSDateFormatteralloc]init];

    [fomatter setDateFormat:@"YYYY-MM-dd HH:mm"];

    NSString *curentDateStr = [fomatterstringFromDate:currentDateTime];

iOS-NSDateFormatter 格式说明

格式化参数如下:
    G: 公元时代,例如AD公元
    yy: 年的后2位
    yyyy: 完整年
    MM: 月,显示为1-12
    MMM: 月,显示为英文月份简写,如 Jan
    MMMM: 月,显示为英文月份全称,如 Janualy
    dd: 日,2位数表示,如02
    d: 日,1-2位显示,如 2
    EEE: 简写星期几,如Sun
    EEEE: 全写星期几,如Sunday
    aa: 上下午,AM/PM
    H: 时,24小时制,0-23
    K:时,12小时制,0-11
    m: 分,1-2位
    mm: 分,2位
    s: 秒,1-2位
    ss: 秒,2位

    S: 毫秒

常用日期结构:
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
MM dd yyyy


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值