Date, Time & Locale Flashcards

1
Q

Pkg a tridy pro date a time
Vlastnosti (2)

A

java.time
LocalDate
LocalTime
LocalDateTime

immutable, thread safe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Datumovo casove metody porovnavani (2)

A

dt.isBefore(), dt.isAfter()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Datumovo casove metody vytvareni - ted; konkretni datum

A

LocalDate.now()
LocalDate.of(2023, 12, 31)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Datumovo casove metody zmeny/ziskani minuty, hodiny, dne v mesici, … (4)

A

hours, secords, daysOfMonth, …:
dt.withXXX(), dt.getXXX()
dt.plusXXX(), dt.minusXXX()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

LocalDateTime
- z date a time (2)
- na date, na time

A

LocalDateTime.of(date, time)
date.atTime(time)
ldt.toLocalDate()
ldt.toLocalTime()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Konstanty: leden

A

Month.JANUARY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Tridy pro:
casove rozmezi v nanosekundach
casove rozmezi v jednotkach
casove razitko

A

Duration - pro logy
Period - pro aplikace
Instant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Duration - metody porovnani

A

Duration.between(x, y)
Duration.isNegative(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Duration - prevod z minut a na minuty

A

Duration.ofMinutes(x)
duration.toMinutes()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Vytvoreni datumu se zonou
Zona:
Londyn
GMT + 5
systemova

A

ZonedDateTime.of(date, zoneId)
ZoneId.of(“Europe/London”)
ZoneId.of(“GMT+5”)
ZoneId.getSystemDefault()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Prevedeni datumu se zonou na jinou zonu
Ziskej offset oproti greenwichi

A

zonedDateTime.withZoneSameInstant(zoneId)
zonedDateTime.getOffset()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Lokale : pro Velkou Britanii - s librami vs s eurem
pro francouzsky langugage tag
pro francii konstantou
systemove

A

new Locale(“en”, “GB”)
new Locale(“en”, “GB”, “EURO”)
Locale.forLanguageTag(“fr-FR”)
Locale.FRANCE
Locale.getDefault()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Tvorba formatovace pro menu, pro procenta, pro cisla, pro cisla zkracena (napr 1000 = 1 k)
Co je vzdy parametrem?

A

NumberFormat.getCurrencyInstance()
NumberFormat.getPercentInstance() - zahazuje desetinky
NumberFormat.getNumberInstance()
NumberFormat.getCompactNumberInstance(locale, Style.SHORT)
locale

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Prevod cisla na formatovany text
Prevod formatovaneho textu na cislo + co vraci

A

numberFormat.format(x)
numberFormat.parse(s) - vraci Wrapper class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Datum na String: trida, patterny pro: rok, mesic, den, den v tydnu
Escapovani patternu <rok> je rok, mesic je <mesic></mesic></rok>

A

DateTimeFormatter
yyyy,MM,dd,EEEE
“yyyy’ je rok, mesic je ‘MM”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

DateTimeFormatter - typy formatovani

A

FormatStyle.SHORT, MEDIUM, LONG, FULL

17
Q

DateTimeFormatter - vytvor pro pattern a pro datum(2)

A

DTF.ofPattern(pattern, locale)
DTF.ofLocalizedDateTime(formatStyle, locale)
DTF.ofLocalizedDate(formatStyle).localizedBy(locale)

18
Q

Metody prevodu Stringu na datum a datumu na String

A

LocalDate.parse(“date”, dateTimeFormatter)
date.format(dateTimeFormatter)

19
Q

Resource bundle - filename, filename pro locale en,GB
Kdy se pouzije ten bez locale

A

name.properties
name_en_GB.properties
default se pouzije, pokud nezadam locale, nebo klic neni v lokalizovanem bundlu

20
Q

Radek resource bundlu pro pattern, ktery je <X> loves <Y>
Jak se rika takovym parametrum</Y></X>

A

pattern={0} loves {1}
substitution parameters

21
Q

Otevri resource bundle resources/names/name_en_GB.properties
a ziskej hodnotu klice pattern

A

RB b = ResourceBundle.getBundle(resources.names.name, new Locale(“en”, “GB”))
b.getString(“pattern”);

22
Q

Alternativni trida k ResourceBundle, v cem se lisi

A

Properties, muze cist z ruznych zdroju

23
Q

Prevedeni patternu se substitution params na String

A

MessageFormat.format(“{0} loves {1}”, person0, person1);

24
Q

Jak ziskam z datumu
- cislo mesice
- enum mesice

A

localDate.getMonthValue()
localDate.getMonth()

25
Q

Jake cislo ma Calendar.APRIL konstanta?
Jake cislo ma duben v LocalDate?

A

4
3 (LocalDate pocita od 0)