關於時間格式轉date的問題

2021-07-24 11:36:34 字數 700 閱讀 4385

因為專案後台傳回的字串為yyyy:mm:dd hh:mm:ss格式,在專案中需要轉換為自己需要的nsdate型別,所以使用方法:

+ (nsdate

*)yc_stringwithtimestring:(

nsstring

*)string withformat:(

nsstring

*)format

在此過程中遇到乙個問題 就是 使用

[formatter 

datefromstring

:string];轉換出來的 strings 為nil 糾結了很久 網上搜了 很多都是提示新增

[formatter 

setlocale

:[[nslocale

alloc

] initwithlocaleidentifier

:@"en_us"

]];[formatter 

settimezone

:[nstimezone

timezonewithabbreviation

:@"utc"

]];這兩句**,但是還是不行!

最後發現問題 setdateformat的格式 必須和字串的保持一致 就是:字串是yyyy:mm:dd hh:mm:ss 那麼傳入的format也必須是yyyy:mm:dd hh:mm:ss.

此筆記記自己的踩過的坑 }

關於Date型別 時間戳格式轉換方法

1 註解 需要引入 jackson jar包 在實體類屬性上加註解,必須依賴實體類 資料 後端 到 前端 timezone gmt 8 中國時區 8小時 jsonformat pattern yyyy mm dd hh mm ss timezone gmt 8 private date bookda...

js中時間戳轉date字串格式

轉換日期格式 時間戳轉換為datetime格式 function changedateformat cellval var strtime 2014 04 23 18 55 49 123 var date newdate strtime 傳入乙個時間格式,如果不傳入就是獲取現在的時間了,這樣做不相容...

關於毫秒數轉date型別的細節問題

dateformat format new dateformat yyyy mm dd hh mm ss long a long.parselong 1459236542000 system.out.println a date date new date a system.out.println ...