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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takuji Nishibayashi
July 10, 2024
Technology
1.1k
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
320
HiltのCustom Componentについて
takuji31
0
440
java.timeをAndroidで使う
takuji31
0
220
KSPを使ってコード生成
takuji31
0
490
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.3k
kotlinx.serialization
takuji31
0
710
kanmoba-returns-02.pdf
takuji31
0
300
AndroidXとKotlin Coroutines
takuji31
0
450
Other Decks in Technology
See All in Technology
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
27
15k
品質と信頼性を地続きにする
grimoh
0
710
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
270
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
2
940
AIエージェントの一手は 誰も見ていない - Falco拡張OSS「Prempti」とeBPFで サーバーレス実行基盤を二層防御する
keitah
0
140
CLIライブラリ開発を支える技術
htnabe
0
120
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
9
4.4k
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
1
2.8k
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
1
400
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
31
26k
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
4
230
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
KATA
mclloyd
PRO
35
15k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Navigating Weather and Climate Data
rabernat
0
520
Odyssey Design
rkendrick25
PRO
2
810
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
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