Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
kotlinx.datetime 使ってみた
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takuji Nishibayashi
July 10, 2024
Technology
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
kotlinx.datetime 使ってみた
Takuji Nishibayashi
July 10, 2024
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
170
CameraX使ってみた
takuji31
0
330
HiltのCustom Componentについて
takuji31
0
450
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
500
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
710
kanmoba-returns-02.pdf
takuji31
0
310
AndroidXとKotlin Coroutines
takuji31
0
460
Other Decks in Technology
See All in Technology
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
120
Meet AgentCore Identity Consent Portal
hironobuiga
3
190
AIは爆速なのに、私が詰まっていた話 ― 音声入力と鳴くマスコットでボトルネックを削る
yama3133
0
530
今こそ知りたいAmplifyGen2
mkdev10
2
150
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
870
Codex概要
ymiya55
0
440
20260930_Gemma4_Hands-on
tsho
0
230
並行性の問題を防げ!実践トランザクション入門
occhi
0
280
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
310
LocalStack を使ったサーバーレスアプリケーション開発 / Serverless Development with LocalStack
kakakakakku
0
260
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
360
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
430
Featured
See All Featured
BBQ
matthewcrist
90
10k
For a Future-Friendly Web
brad_frost
184
10k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
460
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Abbi's Birthday
coloredviolet
4
10k
Believing is Seeing
oripsolob
1
240
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
From π to Pie charts
rasagy
1
390
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
860
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Making Projects Easy
brettharned
120
6.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Transcript
kotlinx.datetime 使ってみた Sansan モバイル勉強会 vol.1 Takuji Nishibayashi(@takuji31)
自己紹介 西林 拓志 (にしばやし たくじ ) Twitter/GitHub takuji31 Sansan 株式会社
2024/04/01 入社 技術本部 Mobile Application グループ 6 月〜 Eight Android チーム テックリード Android (2009〜 ) Kotlin (2014〜 ) 1
日付処理してますか? 2
Kotlin JVM や Android で日付関連クラスといえば 3
java.util.Date / java.util.Calendar 4
java.time (JSR310) 5
今なら java.time を使うことが多い 6
see. java.time を Android で使う 7
Kotlin Multiplatform だとどうか? 8
kotlinx.datetime 9
Kotlin Multiplatform 対応の公式ライブラリー 10
kotlinx.serialization 対応 11
JVM/JS/WASM/Native 等実装あり 12
github.com/Kotlin/kotlinx-datetime 13
kotlinx.datetime の使い方 14
build.gradle.kts repositories { mavenCentral() } kotlin { sourceSets { commonMain
{ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0") } } } } 15
kotlinx.datetime のクラスたち Instant Clock LocalDateTime LocalDate LocalTime TimeZone Month DayOfWeek
etc. 16
今回はよく使いそうなクラスだけ紹介 17
Instant 18
エポック秒を持っているクラス 19
いわゆる Date っぽいやつ 20
使い方 val now = Clock.System.now() now.epochSeconds // 1970/01/01 00:00:00からの経過秒数 now.toEpochMilliseconds()
// 1970/01/01 00:00:00からの経過ミリ秒数 now.nanosecondsOfSecond // ナノ秒 val secondLater = now + 1.seconds// 1秒後 val sameTimeOfYesterday = now - 1.days // 昨日の同じ時間 21
LocalDateTime 22
タイムゾーンを含まない DateTime 23
LocalDate + LocalTime 24
使い方 val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) now.year // 2024 now.month //
Month.JULY now.monthNumber // 7 now.date // 10 now.hour // 12 now.minute // 34 now.second // 56 25
注意点 26
まだ alpha なので破壊的変更入るかも? 27
JVM では java.time を使った方がいいかも? 28
実装が JVM だと java.time のラッパー 29
java.time みたいに ZonedDateTime や OffsetDateTime といったものはない 30
→ Instant を適宜タイムゾーンに応じて変換する 31
LocalDateTime は直接計算できない 32
→ Instant にしてから計算して戻す 33
Instant にしてから計算して戻す val timeZone = TimeZone.currentSystemDefault() val now = Clock.System.now().toLocalDateTime(timeZone)
val sameTimeInTomorrow = (now.toInstant(timeZone) + 1.days) .toLocalDateTime(timeZone) 34
Enjoy kotlinx.datetime 35