Created
September 29, 2022 03:40
-
-
Save dino-su/c8edf1c206dd974b282326f3b9641ccc to your computer and use it in GitHub Desktop.
Compose TextClock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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