String date = (String) android.text.format.DateFormat.format("yyyy-MM-dd HH:mm:ss", new java.util.Date());
Is some device work ok. But in other devices I get:
2015-12-24 HH:28:24
In devices that not work if I change (HH) - > (hh) works. But I need hour in 24 hour mode.
Try to use kk
instead of hh
for instance:
String date = (String) android.text.format.DateFormat.format("yyyy-MM-dd kk:mm:ss", new java.util.Date());
Or use SimpleDateFormat
:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
formatter.format(new Date(System.currentTimeMillis()));
Check out documentation: SimpleDateFormat
H - Hour in day (0-23)
k - Hour in day (1-24)
K - Hour in am/pm (0-11)
h - Hour in am/pm (1-12)
You can use as:
Date dt = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String check = dateFormat.format(dt);
System.out.println("DATE_TO_FROM_DATEBASE " +
arrayOfStringDate[d].toString());
System.out.println("CURRENT_DATE " + check);
Hope so this may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With