本文介紹了在 iOS 上更改日期格式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一些這種格式的日期:
I have some dates in this format :
2012-06-26 12:00:00 +0000
我想要做的就是將它們轉換成這種格式:
and what i want to do is convert them in this format :
Jun 26, 2012 12:00:00 AM
在 obj-c 上是否有一種簡單的方法可以做到這一點,或者我必須解析所有核心內容,并為此創建自己的函數?如果是的話,任何想法都會是什么樣子,因為我是 iOS 新手.非常感謝您閱讀我的帖子:D
Is there an easy way to do this on obj-c , or i must parse everything hardcore , and make my own function for this? If yes , any ideas how this would look like , cause i am new on iOS. Thank you very much for reading my post :D
推薦答案
要將 1 個字符串轉換為另一個字符串,請使用以下代碼
To convert from 1 string to the other use the following
NSString *inputString = @"2012-06-26 12:00:00 +0000";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss z"];//input
NSDate *date = [formatter dateFromString:inputString];
[formatter setDateFormat:@"MMM dd, yyyy hh:mm:ss a"];
NSString *outputString = [formatter stringFromDate:date];
NSLog(@"output : %@",outputString);
這篇關于在 iOS 上更改日期格式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!