How do you format correctly according to the device configuration a date and time when having year, month, day, hour and minute?
相关问题
- 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:
And when you are accessing passed variables:
In my opinion,
android.text.format.DateFormat.getDateFormat(context)
makes me confused because this method returnsjava.text.DateFormat
rather thanandroid.text.format.DateFormat
- -".So, I use the fragment code as below to get the current date/time in my format.
In addition, you can use others formats. Follow DateFormat.
Avoid j.u.Date
The Java.util.Date and .Calendar and SimpleDateFormat in Java (and Android) are notoriously troublesome. Avoid them. They are so bad that Sun/Oracle gave up on them, supplanting them with the new java.time package in Java 8 (not in Android as of 2014). The new
java.time
was inspired by the Joda-Time library.Joda-Time
Joda-Time does work in Android.
Search StackOverflow for "Joda" to find many examples and much discussion.
A tidbit of source code using Joda-Time 2.4.
Standard format.
Localized format.
This will do it:
I use it like this:
Date to Locale date string:
Options:
- > Dec 31, 1969
-> Dec 31, 1969 4:00:00 PM
-> 4:00:00 PM