在 Android 应用程序中显示当前时间和日期 [英] Display the current time and date in an Android application

查看:28
本文介绍了在 Android 应用程序中显示当前时间和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Android 应用程序中显示当前日期和时间?

How do I display the current date and time in an Android application?

推荐答案

好吧,没有那么难,因为有几种方法可以做到这一点.我假设你想把当前日期 &时间进入 TextView.

Okay, not that hard as there are several methods to do this. I assume you want to put the current date & time into a TextView.

String currentDateTimeString = java.text.DateFormat.getDateTimeInstance().format(new Date());

// textView is the TextView view that should display it
textView.setText(currentDateTimeString);

在文档中可以轻松找到更多内容这里.您可以在此处找到有关如何更改用于转换的格式的更多信息.

There is more to read in the documentation that can easily be found here . There you'll find more information on how to change the format used for conversion.

这篇关于在 Android 应用程序中显示当前时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆