NSDate to String

Programming/Objective-C 2012.07.23 19:45

PatternResult (in a particular locale)
yyyy.MM.dd G 'at' HH:mm:ss zzz1996.07.10 AD at 15:08:56 PDT
EEE, MMM d, ''yyWed, July 10, '96
h:mm a12:08 PM
hh 'o''clock' a, zzzz12 o'clock PM, Pacific Daylight Time
K:mm a, z0:00 PM, PST
yyyyy.MMMM.dd GGG hh:mm aaa01996.July.10 AD 12:08 PM




-(void) date1{
      // output : 7/23/12
      NSDate *today = [NSDate dateWithTimeIntervalSinceNow:0];
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateStyle:NSDateFormatterShortStyle];
      NSString *dateString = [dateFormat stringFromDate:today];
      NSLog(@"date1 : %@", dateString);
}

-(void) date2{
      // output : 07/23/2012 07:36PM
      NSDate *today = [NSDate date];
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateFormat:@"MM/dd/yyyy hh:mma"];
      NSString *dateString = [dateFormat stringFromDate:today];
      NSLog(@"date2 : %@", dateString);
      
}
-(void) date3{
      // output : Monday July 23, 2012
      NSDate *today = [NSDate date];
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
      NSString *dateString = [dateFormat stringFromDate:today];
      NSLog(@"date3 : %@", dateString);
}

-(void) date4{
      // output : 7:38 PM, GMT+09:00
      NSDate *today = [NSDate date];
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateFormat:@"h:mm a, zzz"];
      NSString *dateString = [dateFormat stringFromDate:today];
      NSLog(@"date4 : %@", dateString);
}

-(void) date5{
      // output : 월요일 7월 23, 2012
      NSDate *date = [NSDate date];
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
      [dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ko_kr"]];
      NSString *dateString = [dateFormat stringFromDate:date];
      NSLog(@"date5 : %@", dateString);
}


저작자 표시 비영리 변경 금지
신고
    

설정

트랙백

댓글


티스토리 툴바