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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takuji Nishibayashi
July 10, 2024
Technology
0
970
kotlinx.datetime 使ってみた
Takuji Nishibayashi
July 10, 2024
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
130
CameraX使ってみた
takuji31
0
270
HiltのCustom Componentについて
takuji31
0
350
java.timeをAndroidで使う
takuji31
0
170
KSPを使ってコード生成
takuji31
0
430
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3k
kotlinx.serialization
takuji31
0
670
kanmoba-returns-02.pdf
takuji31
0
270
AndroidXとKotlin Coroutines
takuji31
0
410
Other Decks in Technology
See All in Technology
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
550
Context Engineeringの取り組み
nutslove
0
340
30万人の同時アクセスに耐えたい!新サービスの盤石なリリースを支える負荷試験 / SRE Kaigi 2026
genda
4
1.3k
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
230
GitHub Issue Templates + Coding Agentで簡単みんなでIaC/Easy IaC for Everyone with GitHub Issue Templates + Coding Agent
aeonpeople
1
220
配列に見る bash と zsh の違い
kazzpapa3
1
150
Oracle Cloud Observability and Management Platform - OCI 運用監視サービス概要 -
oracle4engineer
PRO
2
14k
登壇駆動学習のすすめ — CfPのネタの見つけ方と書くときに意識していること
bicstone
3
100
SREのプラクティスを用いた3領域同時 マネジメントへの挑戦 〜SRE・情シス・セキュリティを統合した チーム運営術〜
coconala_engineer
2
650
Red Hat OpenStack Services on OpenShift
tamemiya
0
110
データの整合性を保ちたいだけなんだ
shoheimitani
8
3.1k
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.1k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
160
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
RailsConf 2023
tenderlove
30
1.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