Skip to content

Instantly share code, notes, and snippets.

@dino-su
Created September 29, 2022 03:40
Show Gist options
  • Save dino-su/c8edf1c206dd974b282326f3b9641ccc to your computer and use it in GitHub Desktop.
Save dino-su/c8edf1c206dd974b282326f3b9641ccc to your computer and use it in GitHub Desktop.
Compose TextClock
@Composable
fun ClockText() {
val currentTimeMillis = remember {
mutableStateOf(System.currentTimeMillis())
}
LaunchedEffect(key1 = currentTimeMillis) {
while (true) {
delay(250)
currentTimeMillis.value = System.currentTimeMillis()
}
}
Box() {
Text(
text = DateUtils.formatDateTime(LocalContext.current, currentTimeMillis.value, DateUtils.FORMAT_SHOW_TIME),
modifier = Modifier.padding(8.dp, 8.dp),
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.subtitle2
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment