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
Easy, you can dissect the time to get separate values for current time, as follows:
Same goes for the date, as follows:
Try with this way All formats are given below to get date and time format.
You could use:
There are plenty of constants in Calendar for everything you need.
Edit:
Check Calendar class documentation
If you want to get the date and time in a specific pattern you can use the following:
Actually, it's safer to set the current timezone set on the device with
Time.getCurrentTimezone()
, or else you will get the current time in UTC.Then, you can get all the date fields you want, like, for example:
See android.text.format.Time class for all the details.
UPDATE
As many people are pointing out, Google says this class has a number of issues and is not supposed to be used anymore:
If you need current date,
If you need current time,