昨天遇到個(gè)坑倔监,字符串轉(zhuǎn)時(shí)間戳的時(shí)候發(fā)現(xiàn)結(jié)果有的為nil,有的正常;代碼如下:
let dateFormate = NSDateFormatter()
dateFormate.dateFormat = "yyyy-MM-dd hh:mm:ss.0"
publishDate = dateFormate.dateFromString(json["pubTime"].stringValue)
服務(wù)端返回的數(shù)據(jù)為 2016-10-27 15:34:19.0
粒梦;粗看沒(méi)什么不對(duì),后面又對(duì)了文檔發(fā)現(xiàn)hh
表示的是12小時(shí)制,HH
才是24小時(shí)≥┦担現(xiàn)在補(bǔ)上NSDateFormatter的詳細(xì)文檔匀们,供大伙查閱。
a: AM/PM (上午/下午)
A: 0~86399999 (一天的第A微秒)
c/cc: 1~7 (一周的第一天, 周天為1)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat (星期幾簡(jiǎn)寫(xiě))
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday (星期幾全拼)
d: 1~31 (月份的第幾天, 帶0)
D: 1~366 (年份的第幾天,帶0)
e: 1~7 (一周的第幾天, 帶0)
E~EEE: Sun/Mon/Tue/Wed/Thu/Fri/Sat (星期幾簡(jiǎn)寫(xiě))
EEEE: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday (星期幾全拼)
F: 1~5 (每月的第幾周, 一周的第一天為周一)
g: Julian Day Number (number of days since 4713 BC January 1) 未知
G~GGG: BC/AD (Era Designator Abbreviated) 未知
GGGG: Before Christ/Anno Domini 未知
h: 1~12 (0 padded Hour (12hr)) 帶0的時(shí), 12小時(shí)制
H: 0~23 (0 padded Hour (24hr)) 帶0的時(shí), 24小時(shí)制
k: 1~24 (0 padded Hour (24hr) 帶0的時(shí), 24小時(shí)制
K: 0~11 (0 padded Hour (12hr)) 帶0的時(shí), 12小時(shí)制
L/LL: 1~12 (0 padded Month) 第幾月
LLL: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec 月份簡(jiǎn)寫(xiě)
LLLL:January/February/March/April/May/June/July/August/September/October/November/December 月份全稱(chēng)
m: 0~59 (0 padded Minute) 分鐘
M/MM: 1~12 (0 padded Month) 第幾月
MMM: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec
MMMM:January/February/March/April/May/June/July/August/September/October/November/December
q/qq: 1~4 (0 padded Quarter) 第幾季度
qqq: Q1/Q2/Q3/Q4 季度簡(jiǎn)寫(xiě)
qqqq: 1st quarter/2nd quarter/3rd quarter/4th quarter 季度全拼
Q/QQ: 1~4 (0 padded Quarter) 同小寫(xiě)
QQQ: Q1/Q2/Q3/Q4 同小寫(xiě)
QQQQ: 1st quarter/2nd quarter/3rd quarter/4th quarter 同小寫(xiě)
s: 0~59 (0 padded Second) 秒數(shù)
S: (rounded Sub-Second) 未知
u: (0 padded Year) 未知
v~vvv: (General GMT Timezone Abbreviation) 常規(guī)GMT時(shí)區(qū)的編寫(xiě)
vvvv: (General GMT Timezone Name) 常規(guī)GMT時(shí)區(qū)的名稱(chēng)
w: 1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of
year starts from the last Sunday of last year) 一年的第幾周, 一周的開(kāi)始為周日,第一周從去年的最后一個(gè)周日起算
W: 1~5 (0 padded Week of Month, 1st day of week = Sunday) 一個(gè)月的第幾周
y/yyyy: (Full Year) 完整的年份
yy/yyy: (2 Digits Year) 2個(gè)數(shù)字的年份
Y/YYYY: (Full Year, starting from the Sunday of the 1st week of year) 這個(gè)年份未知干嘛用的
YY/YYY: (2 Digits Year, starting from the Sunday of the 1st week of year) 這個(gè)年份未知干嘛用的
z~zzz: (Specific GMT Timezone Abbreviation) 指定GMT時(shí)區(qū)的編寫(xiě)
zzzz: (Specific GMT Timezone Name) Z: +0000 (RFC 822 Timezone) 指定GMT時(shí)區(qū)的名稱(chēng)