I am using below code to get the current time in specific format and then want to print the time stamp.
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd hh:mm:ss.ms");
String formattedDate = dateFormat.format(new Date());
Date curDate = null;
try {
curDate = dateFormat.parse(formattedDate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i(Config.TAG,"curDate...... "+curDate);
but when I see the Logcat output “curDate…..” is showing “Mon Jul 13 04:11:51 EDT 1970”
but in the above statement minutes are wrong.
but In my android device, time is showing as “04:40 AM”.
I am unable to figure out why the above method capturing “29” minutes delay.??
Pl. let me know is that the proper way to do this.
let me know if I missed something.
I suspect it’s the “ms” part of your format string which is confusing things. I think that you mean “SS” instead. Also, given that you haven’t got an AM/PM specifier, you probably want a 24-hour format instead of 12-hour:
(Do you really not want the year, by the way?)