[英]The Date format in iOS is not clear…
NSString* lastModified = @"26 Jun 2015 11:16";
activityTime = [dateObject getDateFromString:lastModified andFormat:@"dd MMM yyyy HH:mm" toFormat:@"dd MMM, yyyy"];
我使用的格式有什么問題? 我總是把activityTime變量設置為nil。
我還檢查了蘋果文檔...我的用例給出了相同的格式。 但是它沒有用。
需要一些見解!
提前致謝...
NSString *str = @"26 Jun 2015 11:16"; /// here this is your date with format yyyy-MM-dd
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ; // here we create NSDateFormatter object for change the Format of date..
[dateFormatter setDateFormat:@"dd MMM yyyy HH:mm"]; //// here set format of date which is in your output date (means above str with format)
NSDate *date = [dateFormatter dateFromString: str]; // here you can fetch date from string with define format
dateFormatter = [[NSDateFormatter alloc] init] ;
[dateFormatter setDateFormat:@"dd MMM, yyyy"];// here set format which you want...
NSString *convertedString = [dateFormatter stringFromDate:date]; //here convert date in NSString
NSLog(@"Converted String : %@",convertedString);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.