How can I get the current time and date in an Android app?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Try this code it display current date and time
You can (but no longer should - see below!) use android.text.format.Time:
From the reference linked above:
NOTE 1: It's been several years since I wrote this answer, and it is about an old, Android-specific and now deprecated class. Google now says that "[t]his class has a number of issues and it is recommended that GregorianCalendar is used instead".
NOTE 2: Even though the
Time
class has atoMillis(ignoreDaylightSavings)
method, this is merely a convenience to pass to methods that expect time in milliseconds. The time value is only precise to one second; the milliseconds portion is always000
. If in a loop you doThe resulting sequence will repeat the same value, such as
1410543204000
, until the next second has started, at which time1410543205000
will begin to repeat.For the current date and time, use:
Which outputs:
There are several options as Android is mainly Java, but if you wish to write it in a textView, the following code would do the trick:
To ge the current time you can use
System.currentTimeMillis()
which is standard in Java. Then you can use it to create a dateAnd as mentioned by others to create a time