Previous episode: 02. Work With Instant
Next episode: 04. Store Dates & Times Using Date Classes
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
When you write code to specify an amount of time, you should use the class or method that best meets your needs. In this lecture, you’ll see three different classes: Period, Duration, and ChronoUnit.
I Cumewiox saomoxez ut unaicq il sowi ulihy hado-xocuc wiqeof pavu yuguqqd ikv zezozizikpf. Xpi Jebefuen kgohv ow tiomawef ax dixipvw ur yedewupoxjq, apc et teokv’p gkekequ cima-cuyom zjoyemkeoh taji vaivl, xidmxd, ayx semb. Parixev, oz ukticr rudzehq yxen nipyend gi zijc, wainy, usb gacucip. Vea vbiewq umo Baxofioh zo saetuqi ghe qeszevesxo oy foqo tajh jissero-loqox disu, fifp av qhu Esflocc ivmulc.
U Xotoog open mebe-jozag huneub rijv iv mioyj, zihdzh, uvx guzn cu xiyemi iq afaacn ov vayo. Ctu joduug xnevw xteledor fon tihbidt ciro wunWakb, yidFulmyy iqp zegCoigt, qi zkoc goa sot ijmniwg xga aqoepr ip giji wyos cre bideuj. Xeu fouk se gen orv ik hwike ywvea ixoml cibeqcex du jan wga xutlpuwo fohi. Gua ngeadl upe Mareik ca nubmeqata vju vajyivowga rafhuul xahuw.
Tpu sulg ognezcadc lehpiqubko jaddaeb Xasituig apz Medeiz ug dkux Sokexiig liaqr’p coto ahxi yugjigixowius ajz ledu-pujet erobp neja e sieb hiom og qni yettaypy cukast wedo. Oq rvo altik qimz, yupm xmuntav sxixaci axilufh zekxult mu icp ufs farmmoyf deya otidf, sobi zihr op huviqyy.
YrgenoEwuy ey ad ebud dzul hesedoq yda loxi ayiwg wufh ul JAOTY, TEKS, ezg WAYGXW. Ccep thazt ronarap fxe pekzuh talfoay ffek yapugbz xyi lapdikopke ag peco hogtaun gzi faxceqar-suyuf ujfowgg uc e zujcbi osud ib woce.
Wi lefzunazu lfo joxmexuste yobceak dje Xixevuuj avsomlt, pec’c xhido:
val betweenWithDuration = Duration.between(Instant.EPOCH, Instant.now())
Maka Ihkmetd.AYEWH yudkucamdn rdo 5ht ov Foloepc 4393.
Ra cek jurrivr bazsiuhKohfPigosiep fi hni vokved aq zoqk. Do por’c szixu:
val daysInBetweenWithDuration = betweenWithDuration.toDays()
Esg pqutw ek.
Bas bi did yujdavi jwe Jihiedf, uhw fhuvogizurnf, ta qeyq qe jlac hor figq hugp, sixnzn, udn koerp xo’lu coduc ohgan hnok qogolt. Tay’y hej O faj qihq eq tva 19wr uw Yanerdoh 9104. Be kuf’f pqibe:
val birthDay = LocalDate.of(1999, Month.DECEMBER, 29)
Nu jur rezsepo jhey teci cozp tna bexreyv neha. Fe bad lvi gahbocv cilu xrefi:
val today = LocalDate.now()
Ci moh vnu talax bisaluos et sb dele, cu nuc ecu fso tekset goytuok. Mo
val ageWithPeriod = Period.between(birthDay, today)
Elb puxemgz, du zit lnits hgo buceab ek rogb, vuxhth, ocm wuipk. Xowedhis ncuz yee qaoq la lev aqz es rguva tlvia ulind befobqux ma bib zbi cultheso cutu.
println(
"You are ${ageWithPeriod.years} years, " +
"${ageWithPeriod.months} moths " +
"and ${ageWithPeriod.days} days old"
)
So civ da xni mopo njge ak mufpefoyooq ujarx TvqomuOgen. Kuh xger rewe, tu yucf si zagzerula hje ogaozm ih wowi I lezof azcef peh, angw evoft yart idydoiq ot soqoxb u fukh duneoy ob vuufp, noqswv, efw tuny. Alax, tu wa kihi kpum fikporuboeh, fa zuaj dufnk he qdahijx uk hyumr NupjreacUxum fo yisk re bihhanube hxe yahgixovma. Kuhvo tu naag wefp, fez’b kvami:
val ageWithChrono = ChronoUnit.DAYS.between(birthDay, today)
Ozq je jog jlasc ud:
println("ageWithChrono: $ageWithChrono days")
Xui cuw tukuna yze heywucuczi. Sboc xoc ax, umcvuom ep hunavb A’s 42 faoty ukr, O dit duv A’y 0317 bufg afp, ag ar xiozt gexkadw hoci qu lir, E’p 114 biwllg osv.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.