Latest 0.0.3
Homepage https://github.com/dvlproad/CJFoundation
License MIT
Platforms ios 7.0, requires ARC
Frameworks UIKit

CJFoundation

自定义的UIFoundation的Extension

NSDate

①、NSString转NSDate为nil

举例:2017-04-17 19:49:52

    NSString *currentTime = @"2017-04-17 19:49:52";

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *currentDate = [dateFormatter dateFromString:currentTime];

错误可能原因:

①、dateFormatter.dateFormat格式不对,比如string里面有时分秒,而dateFormatter.dateFormat却只写到@"yyyy-MM-dd";

②、还是dateFormatter.dateFormat格式不对,比如大小写错误,如HH被写成了小写了。即dateFormatter.dateFormat = @"yyyy-MM-dd hh:mm:ss"也是可能会造成错误的。因为小写的hh是代表跟随者系统采用的小时制,而上面的我们的值是24小时制,所以应该用大写的HH。即注意的是formatter的格式,如果是小写的"hh",那么时间将会跟着系统设置变成12小时或者24小时制。大写的"HH",则强制为24小时制。

扩展:必须知道的事

参考: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: 毫秒
Z:GMT

常用的时间格式有:
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
MM dd yyyy 

Latest podspec

{
    "name": "CJBaseUtil",
    "version": "0.0.3",
    "summary": "u81eau5b9au4e49u7684u57fau7840u5de5u5177u7c7b",
    "homepage": "https://github.com/dvlproad/CJFoundation",
    "license": "MIT",
    "authors": "dvlproad",
    "description": "1u3001CJSortedAndSearchUtiluff1au641cu7d22u548cu6392u5e8fu7684u5de5u5177u7c7bnn A longer description of CJBaseUtil in Markdown format.nn * Think: Why did you write this? What is the focus? What does it do?n * CocoaPods will be using this to generate tags, and improve search results.n * Try to keep it short, snappy and to the point.n * Finally, don't worry about the indent, CocoaPods strips it!",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/dvlproad/CJFoundation.git",
        "tag": "CJBaseUtil_0.0.3"
    },
    "frameworks": "UIKit",
    "requires_arc": true,
    "subspecs": [
        {
            "name": "CJSortedAndSearchUtil",
            "source_files": "CJBaseUtil/CJSortedAndSearchUtil/**/*.{h,m}",
            "dependencies": {
                "PinYin4Objc": [
                    "~> 1.1.1"
                ]
            }
        },
        {
            "name": "CJApp",
            "source_files": "CJBaseUtil/CJApp/**/*.{h,m}"
        },
        {
            "name": "CJDevice",
            "source_files": "CJBaseUtil/CJDevice/**/*.{h,m}"
        },
        {
            "name": "CJLog",
            "source_files": "CJBaseUtil/CJLog/**/*.{h,m}"
        },
        {
            "name": "PrivateSetting",
            "source_files": "CJBaseUtil/PrivateSetting/**/*.{h,m}"
        }
    ]
}

Pin It on Pinterest

Share This