본문 바로가기
iOS/iOS

DateFormatter

by 패쓰킴 2022. 11. 3.
728x90

한국에 맞게 원하는 format으로 날짜 만들기

NSString * StringDate = @"2022-11-05";
NSDateFormatter * dateFormatter = [NSDateFormatter new];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"ko_KR"]];

string으로 되어 있는 날짜 형식에 맞게 format을 맞춘다

[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate * date = [dateFormatter dateFromString: stringDate];
// 2022-11-05 00:00

이 'date'를 원하는 형식의 format으로 만들어 준다.

[dateFormatter setDateFormat:@"MM월 dd일 EEEE"];
NSString * myDate = [dateFormatter stringFromDate:date];
// 11월 05일 토요일

참고:

https://skyfe.tistory.com/entry/NSDate%EC%99%80-NSDateFormatter-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-04

https://itstudentstudy.tistory.com/104

728x90

'iOS > iOS' 카테고리의 다른 글

UIBezierPath  (0) 2022.11.08
UICollectionView  (0) 2022.11.04
UIPickerView  (0) 2022.11.02
navigation stack에서 특정 VC 삭제  (0) 2022.11.02
UIScrollView  (0) 2022.11.01

댓글