ebook img

php|architect's Guide to Date and Time Programming PDF

150 Pages·2009·2.56 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview php|architect's Guide to Date and Time Programming

php|architect’s Guide to ff Date and Time Programming ff ffi Derick Rethans Licensed to: Blake Hartle [email protected] User #60389 php|architect’s Guide to Date and Time Programming byDerickRethans http://phpdatebook.com php|architect’sGuidetoDateandTimeProgramming ContentsCopyright©2008–2009DerickRethans–AllRightsReserved Bookandcoverlayout,designandtextCopyright©2004-2008MarcoTabini&Associates,Inc.–AllRightsReserved FirstEdition:February2009 ISBN:978-0-9738621-5-7 ProducedinCanada PrintedintheUnitedStates Nopartofthisbookmaybereproduced,storedinaretrievalsystem,ortransmittedinanyformor bymeanswithoutthepriorwrittenpermissionofthepublisher,excetinthecaseofbriefquotations embeddedincriticalreviewsorarticles. Disclaimer Althougheveryefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe informationcontainedtherein,thisbookisprovided“as-is”andthepublisher,theauthor(s),theirdis- > tributorsandretailers,aswellasallaffiliated,relatedorsubsidiarypartiestakenoresponsibilityforany m o inaccuracyandanyandalldamagescaused,eitherdirectlyorindirectly,bytheuseofsuchinforma- k.c tion.Wehaveendeavouredtoproperlyprovidetrademarkinformationonallcompaniesandproducts oo b mentionedinthebookbytheappropriateuseofcapitals.However,wecannotguaranteetheaccuracy e w ofsuchinformation. o w w. w MarcoTabini&Associates,TheMTAlogo,php|architect,thephp|architectlogo,NanoBookandthe w < NanoBooklogoaretrademarksorregisteredtrademarksofMarcoTabini&Associates,Inc. k o o B e w! Writtenby DerickRethans o W Publishedby MarcoTabini&Associates,Inc. m 28BombayAve. o Toronto,ONM3H1B7 d fr Canada oa nl w (416)630-6202/(877)630-6202 o D [email protected]/www.phparch.com Publisher MarcoTabini TechnicalReviewers ScottMacVicarandOleMariusSmestad LayoutandDesign ArbiArzoumani ManagingEditor ElizabethNaramore FinanceandResourceManagement EmanuelaCorso > m o c k. o o b e w o w w. w w < k o o B e w! o W m o d fr a o nl w o D > m o c k. o o b e w o w w. w w < k o o B e w! o W m o d fr a o nl w o D Contents Acknowledgments vii Chapter1—Introduction 1 > m ALittleHistory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 o c Calendars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 ok. o TimeStandards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 eb w TimeStampRange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 o w Timezones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 w. w w ConfiguringPHP’sTimezone . . . . . . . . . . . . . . . . . . . . . . . . . 10 < k TimezoneDatabase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 o o B e Chapter2—ParsingDate/TimeStrings 13 w! o W ParsingStringsContainingTimeInformation . . . . . . . . . . . . . . . . . . 13 m OtherWaysofCreatingaTimestamp . . . . . . . . . . . . . . . . . . . . 18 o d fr Usingmktime()forUTCTimes . . . . . . . . . . . . . . . . . . . . . . . . 21 a o CreatingaDateTimeObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 wnl o ObtainingaDetailedParserResult . . . . . . . . . . . . . . . . . . . . . . . . . 26 D UserSpecificFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 ObtainingaDetailedParserResultfromaUserSpecifiedFormat . . . . . . . 32 ParserQuirks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 ParsingOrder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 TimeStampsHaveImplicitTimezone . . . . . . . . . . . . . . . . . . . . 33 ParsingTimesThatDoNotExist . . . . . . . . . . . . . . . . . . . . . . . 34 vi ” CONTENTS Chapter3—DealingwithTimezones 37 DifferentTypesofTimezones . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 DefaultTimezone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 DateTimeZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 GettingTheOffsetBelongingtoaTimezone . . . . . . . . . . . . . . . . 42 TransitionRulesinTimezones . . . . . . . . . . . . . . . . . . . . . . . . 43 LocationInformationinTimezones . . . . . . . . . . . . . . . . . . . . . 45 AssociatingwithDateTimeobjects . . . . . . . . . . . . . . . . . . . . . . . . . 46 QueryingtheTimezoneDatabase . . . . . . . . . . . . . . . . . . . . . . . . . 48 RestrictingTimezoneListingsbyContinent . . . . . . . . . . . . . . . . 49 AggregatingTimezoneListings . . . . . . . . . . . . . . . . . . . . . . . . 50 ListingTimezoneIdentifiersByCountry . . . . . . . . . . . . . . . . . . 54 Chapter4—RepresentingDate/TimeInformation 57 m> o FormattingTimeStamps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 c k. o ISOWeekDates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 o b e PropertiesofDate/TimeElements . . . . . . . . . . . . . . . . . . . . . . 60 w o CompoundFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 w w. LocalTimevs.UTCTime . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 w w < FormattingLocalTimeStamps . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 k o RetrievingSpecificDate/TimeElements . . . . . . . . . . . . . . . . . . . . . 67 Bo e DateTimeObjectFormatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 w! o W Chapter5—Date/TimeManipulation 73 m o ManipulationWhileParsing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 d fr a ModifyinganExistingDateTimeObject . . . . . . . . . . . . . . . . . . . . . . 75 o nl w SetterMethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 o D RelativeStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 PeriodsandIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Chapter6—PracticalDate/TimeHandling 89 Timezones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 FindingtheNextDSTTransition . . . . . . . . . . . . . . . . . . . . . . . 89 GuessingfromtheBrowser . . . . . . . . . . . . . . . . . . . . . . . . . . 90 CONTENTS ” vii Date-OnlyApplications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 StoringDate/TimeInformationinaDatabase . . . . . . . . . . . . . . . 92 ManipulatingDate/TimeObjects . . . . . . . . . . . . . . . . . . . . . . . . . 99 PreviousWeekInformation . . . . . . . . . . . . . . . . . . . . . . . . . . 99 NextMonthandLastMonth. . . . . . . . . . . . . . . . . . . . . . . . . . 101 ObtainingEvery3rdTuesdayineachMonth . . . . . . . . . . . . . . . . 102 AppendixA—UpgradingtheTimezoneDatabase 107 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 AppendixB—FormatSpecifiers 111 date(),DateTime->format(),idate()andstrftime()formatspecifiers . . . . . 111 Day . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 > m Week . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 o c k. Month . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 o o b Year . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 e w o Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 w w. Timezone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 w w Compound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 < k o DateTime::createFromFormat(), date_create_from_format() and o B date_parse_from_format()formatspecifiers . . . . . . . . . . . . . . . . 116 w! e DateInterval->format()formatspecifiers . . . . . . . . . . . . . . . . . . . . . 117 o W m o AppendixC—ParserFormats 121 d fr TimeFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 a o nl UsedSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 w o 12HourNotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 D 24HourNotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 DateFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 UsedSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 LocalizedNotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 ISO8601Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 CompoundFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 UsedSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 viii ” CONTENTS LocalizedNotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 RelativeFormats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 UsedSymbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Day-basedNotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 > m o c k. o o b e w o w w. w w < k o o B e w! o W m o d fr a o nl w o D > m o c k. o o b e w o w w. w w < k o o B e w! o W m o d fr a o nl w o D

Description:
If your development involves working with dates and times, then this book is a must-have. In this book, Derick Rethans (contributor to PHP’s core date extension and well-known PHP expert) explores in great detail the subtle nuances of working with dates and times. Frequently PHP developers encount
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.