DatesAndTimes.pdf

(219 KB) Pobierz
Date and Time Programming Guide
DateandTimeProgrammingGuide
DataManagement:Dates,Times,&Numbers
2010-02-24
695712232.001.png
AppleInc.
©2002,2010AppleInc.
Allrightsreserved.
ORWRITTEN,EXPRESSORIMPLIED.NoApple
dealer,agent,oremployeeisauthorizedtomake
anymodification,extension,oradditiontothis
warranty.
Somestatesdonotallowtheexclusionorlimitation
ofimpliedwarrantiesorliabilityforincidentalor
consequentialdamages,sotheabovelimitationor
exclusionmaynotapplytoyou.Thiswarrantygives
youspecificlegalrights,andyoumayalsohave
otherrightswhichvaryfromstatetostate.
Nopartofthispublicationmaybereproduced,
storedinaretrievalsystem,ortransmitted,in
anyformorbyanymeans,mechanical,
electronic,photocopying,recording,or
otherwise,withoutpriorwrittenpermissionof
AppleInc.,withthefollowingexceptions:Any
personisherebyauthorizedtostore
documentationonasinglecomputerfor
personaluseonlyandtoprintcopiesof
documentationforpersonaluseprovidedthat
thedocumentationcontainsApple’scopyright
notice.
TheApplelogoisatrademarkofAppleInc.
Nolicenses,expressorimplied,aregranted
withrespecttoanyofthetechnologydescribed
inthisdocument.Appleretainsallintellectual
propertyrightsassociatedwiththetechnology
describedinthisdocument.Thisdocumentis
intendedtoassistapplicationdevelopersto
developapplicationsonlyforApple-labeled
computers.
AppleInc.
1InfiniteLoop
Cupertino,CA95014
408-996-1010
Apple,theApplelogo,Cocoa,Mac,MacOS,
Monaco,Numbers,andObjective-Care
trademarksofAppleInc.,registeredinthe
UnitedStatesandothercountries.
IOSisatrademarkorregisteredtrademarkof
CiscointheU.S.andothercountriesandisused
underlicense.
JavaisaregisteredtrademarkofOracleand/or
itsaffiliates.
TimesisaregisteredtrademarkofHeidelberger
DruckmaschinenAG,availablefromLinotype
LibraryGmbH.
EventhoughApplehasreviewedthisdocument,
APPLEMAKESNOWARRANTYORREPRESENTATION,
EITHEREXPRESSORIMPLIED,WITHRESPECTTO
THISDOCUMENT,ITSQUALITY,ACCURACY,
MERCHANTABILITY,ORFITNESSFORAPARTICULAR
PURPOSE.ASARESULT,THISDOCUMENTIS
PROVIDED“ASIS,”ANDYOU,THEREADER,ARE
ASSUMINGTHEENTIRERISKASTOITSQUALITY
ANDACCURACY.
INNOEVENTWILLAPPLEBELIABLEFORDIRECT,
INDIRECT,SPECIAL,INCIDENTAL,OR
CONSEQUENTIALDAMAGESRESULTINGFROMANY
DEFECTORINACCURACYINTHISDOCUMENT,even
ifadvisedofthepossibilityofsuchdamages.
THEWARRANTYANDREMEDIESSETFORTHABOVE
AREEXCLUSIVEANDINLIEUOFALLOTHERS,ORAL
695712232.002.png
Contents
IntroductiontoDateandTimeProgrammingGuideforCocoa 7
OrganizationofThisDocument 7
SeeAlso 7
Dates 9
AboutDates 9
CreatingDateObjects 9
BasicDateCalculations 10
Calendars,DateComponents,andCalendarUnits 11
CalendarBasics 11
DateComponentsandCalendarUnits 11
CreatingaDatefromComponents 12
CalendricalCalculations 15
AddingComponentstoaDate 15
TemporalDifferences 16
ConvertingfromOneCalendartoAnother 17
UsingTimeZones 19
CreatingTimeZones 19
ApplicationDefaultTimeZone 19
LegacyAPI:NSCalendarDate 21
UsingNSCalendarDate 21
StringRepresentationsofNSDateObjects 22
TheCalendarFormat 22
StringRepresentationsofNSCalendarDateObjects 24
DocumentRevisionHistory 25
2010-02-24 | © 2002, 2010 Apple Inc. All Rights Reserved.
3
695712232.003.png
4
2010-02-24 | © 2002, 2010 Apple Inc. All Rights Reserved.
Listings
Dates 9
Listing1 Creatingdateswithtimeintervals 10
Listing2 Creatingdatesbyaddingatimeinterval 10
Calendars,DateComponents,andCalendarUnits 11
Listing1 Creatingcalendarobjects 11
Listing2 Creatingadatecomponentsobject 12
Listing3 Gettingadate’scomponents 12
Listing4 Creatingadatefromcomponents 12
CalendricalCalculations 15
Listing1 Anhourandahalffromnow 15
Listing2 GettingtheSundayinthecurrentweek 15
Listing3 Gettingthebeginningoftheweek 16
Listing4 Gettingthedifferencebetweentwodates 16
Listing5 Convertingdatecomponentsfromonecalendartoanother 17
2010-02-24 | © 2002, 2010 Apple Inc. All Rights Reserved.
5
695712232.004.png
Zgłoś jeśli naruszono regulamin