Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kotlinx.datetime 使ってみた
Search
Takuji Nishibayashi
July 10, 2024
Technology
1k
0
Share
kotlinx.datetime 使ってみた
Takuji Nishibayashi
July 10, 2024
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
150
CameraX使ってみた
takuji31
0
300
HiltのCustom Componentについて
takuji31
0
370
java.timeをAndroidで使う
takuji31
0
190
KSPを使ってコード生成
takuji31
0
470
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.2k
kotlinx.serialization
takuji31
0
690
kanmoba-returns-02.pdf
takuji31
0
290
AndroidXとKotlin Coroutines
takuji31
0
430
Other Decks in Technology
See All in Technology
【Gen-AX】20260530開催_JJUG CCC 2026 Spring
genax
0
320
Platform Engineering as a Product: Criteria for Improvement and Multi-Tenant Design
kumorn5s
0
470
AI Adaptable なテストを整える工夫 / Ways to Make Your Tests AI-Adaptable
bitkey
PRO
2
200
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
3
630
電子辞書Brainをネットに繋げてみた(自力編)
raspython3
0
410
Javaコミュニティをもっと楽しむための9箇条
takasyou
0
1.1k
関西に縁あるMicrosoft MVPsが語るCopilotの未来
kasada
0
980
大規模災害時でも高い信頼性を維持するアプリケーション基盤の実現/nikkei-tech-talk46
nikkei_engineer_recruiting
0
130
ChatworkとBPaaS 異なる特性で学んだAI機能開発の ベストプラクティス
kubell_hr
2
1.7k
大学生が本気でDatabricksを活用してDiscordサークルをデータ駆動させてみた
phantomjuju
1
320
「コーディング」しない人のための Claude Code 入門 ChatGPT の次の一歩 — 業務に組み込む 育成・共有・自動化
rfdnxbro
2
1.1k
AIガバナンス実践 - 生成AIコネクタのデータ漏洩リスクと実務対策
knishioka
0
160
Featured
See All Featured
A Tale of Four Properties
chriscoyier
163
24k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
280
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Git: the NoSQL Database
bkeepers
PRO
432
67k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
HDC tutorial
michielstock
2
680
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
200
Between Models and Reality
mayunak
4
320
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
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