2011-12-05 16 views
5

में iphone पर वर्तमान समय प्राप्त निम्नलिखित मुझे 9:30 का एक NSDate वस्तु देना चाहिए:एक चुने हुए प्रारूप

NSString *dateString = @"09-30"; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"hh-mm"]; 
NSDate *dateFromString = [[NSDate alloc] init]; 
dateFromString = [dateFormatter dateFromString:dateString]; 

मैं उसी प्रारूप में वर्तमान समय कैसे मिलता है?

उत्तर

15
NSDate *currentTime = [NSDate date]; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"hh-mm"]; 
NSString *resultString = [dateFormatter stringFromDate: currentTime]; 
+1

NSString * resultString = [dateFromatter stringFromDate: मौजूदा समय]; परिवर्तन तिथि तिथि से प्रेषक टाइपर –

+0

thx टाइपिंग के लिए thx – Denis

2
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"hh-mm"]; 
NSDate *currentDate = [NSDate date]; 
NSString *currentDateString = [dateFormatter stringFromDate:currentDate]; 
0
NSDate *currentDate =[NSDate date]; 
//Your formatter goes here. 
NSString *currentTime = [dateFormatter stringFromDate:currentDate]; 
1

NSDate alloc init वर्तमान समय के साथ डेट पैदा करेगा। फिर, आप प्रारूप के लिए NSDateFormatter स्ट्रिंग FromDate का उपयोग कर सकते हैं और उस तारीख को प्रस्तुत कर सकते हैं।

यह:

NSDate *date = [[NSDate alloc] init]; 
NSLog(@"%@", date); 

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"hh-mm"]; 
NSString *dateString = [dateFormatter stringFromDate:date]; 

NSLog(@"%@", dateString); 

आउटपुट:

2011-12-05 07:20:02.994 Craplet[1706:707] 2011-12-05 12:20:02 +0000 
2011-12-05 07:20:02.995 Craplet[1706:707] 07-20 
1
NSDate *today = [[NSDate alloc] init]; 
NSLog(@"today is :%@", date); 

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"hh-mm:ss"]; 
NSString *timeString = [dateFormatter stringFromDate:today]; 

NSLog(@"%@", timeString); 
संबंधित मुद्दे