2005 년 8 월 1 일의 NSDate는 어떻게 작성합니까? 인터넷에서 NSDateComponent를 발견했지만 너무 복잡해 보입니다.NSDate 질문
1
A
답변
6
또 다른 가능성은 NSDateComponents
과 NSCalendar
입니다. 예를 들어 :
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:2000];
[comps setMonth:1];
[comps setDay:1];
[comps setHour:0];
[comps setMinute:0];
[comps setSecond:0];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *startDate = [cal dateFromComponents:comps];
[cal release];
[comps release];
4
0
그것은 오히려 시간대에 따라 다르지만 GMT에서 자정 지난 일분에서 2005 년 8 월 1 일 1122854401. 그래서 당신이 쓸 수있는 UNIX 타임 스탬프는 ...이었다
[NSDate dateWithTimeIntervalSince1970:1122854401];
+0
계산 방법 1122854401 – Fasid
0
Introduction to Date and Time Programming Guide for Cocoa
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:1];
[components setMonth:8];
[components setYear:2005];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:components];
3
NSDateFormatter *myFormatter = [[NSDateFormatter alloc] init];
[myFormatter setDateFormat:@"M/d/yy"];
NSDate *myDate = [myFormatter dateFromString:@"August/01/05"];
0
이 날짜가 "이상한 8 월 2 일 또는 다른 장소에 7 월 31 일 (어쩌면 뭔가 것이라는 사실을 놓치지 마세요 ", 그레고리력을 사용하지 않을 때). 어쩌면 그게 너에게 쓸모가 없을지도 모르지. 그러나 당신은 이것을 알고 있어야합니다. 생각 하시겠습니까? 나는 너무 확신하지 못한다. 예를 들어 NSCalendar getting day difference wrong을 살펴보십시오.
인사말
관련 문제
- 1. 주어진 NSDate 사이의 NSDate
- 2. iPhone - NSDate - NSString - NSDate 사이의 변환
- 3. 있는 NSDate
- 4. NSDate 포맷터
- 5. '있는 NSDate'
- 6. NSDate - timeIntevalSinceDate -
- 7. 내가가 증가되어있는 NSDate/NSDateCompoments로 감소 덕분에 사용 해요있는 NSDate
- 8. NSDate 및 DateByAddingComponents 문제
- 9. NSDate 한 달 어제
- 10. 아이폰있는 NSDate NSDateFormatter
- 11. 있는 NSDate 일정 술어
- 12. NSArray를 NSDate, 오늘으로 정렬합니다.
- 13. NSDate -dateFromString은 nil을 반환합니다.
- 14. NSDate 메모리 문제 (다시)
- 15. NSDate 카운트 다운 일
- 16. NSDate & Memory management
- 17. 코어 데이터 NSDate 비교
- 18. Nsdate 함수 : 목표 사이
- 19. NSString에서 NSDate 가져 오기
- 20. NSDate/NSCalendar 문제
- 21. NSDate 형식 문제
- 22. NSString에서 NSDate 가져 오기
- 23. 범위를 벗어난 NSDate
- 24. UIDatePicker 및 NSDate
- 25. 아이폰 sqlite NSDate 버그
- 26. NSDate/NSDateComponent 문제
- 27. NSDate 반환 날짜 문자열
- 28. strtotime -> NSDate
- 29. 디스크에 nsdate 저장
- 30. NSDate 기본 사용 오류
AFAIK를 0으로 설정하는 데는 아무런 요점이 없습니다. – Chuck
글쎄, 당신이 그렇게한다면, 그것은 의도를 보여줍니다 : "default"보다는 명시 적으로 00:00:00이되기를 원합니다. 의미는 약간 다릅니다. –
기본값은 0으로 문서화되어 있지만, 나는 신경 쓰지 않을 것이다. (나는 체크하지 않았다) – jtbandes