Calendar c = Calendar.getInstance();
SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy");
String formattedDate = date.format(c.getTime());
SimpleDateFormat time24hrs = new SimpleDateFormat("HH:mm");
String intime= time24hrs.format(c.getTime());
The Above code is used for getting the current date and time, the problem is it works well but some times gives wrong current date & time especially it returns previous date and time (wrong date & time) out of 100% it gives 80% correct date and time and 20% gives wrong date and time. I don't what is the bug or problem or misconception in the code. Please Help me to fix this problem. Thanks in Advance.
Try this out:
Where you can have DateFormat patterns such as: