本文介紹了在 iOS 上更改日期格式的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我有一些這種格式的日期:
I have some dates in this format :
2012-06-26 12:00:00 +0000
我想要做的就是將它們轉(zhuǎn)換成這種格式:
and what i want to do is convert them in this format :
Jun 26, 2012 12:00:00 AM
在 obj-c 上是否有一種簡單的方法可以做到這一點(diǎn),或者我必須解析所有核心內(nèi)容,并為此創(chuàng)建自己的函數(shù)?如果是的話,任何想法都會(huì)是什么樣子,因?yàn)槲沂?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 個(gè)字符串轉(zhuǎn)換為另一個(gè)字符串,請(qǐng)使用以下代碼
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);
這篇關(guān)于在 iOS 上更改日期格式的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!