Friends,
I was intended to know how to implement the date and time functions for android and java.
I’m developing an application which shows the posted date of images. I’m showing that date in a list view. For example. I’m showing something like // posted on : 20/3/2012. Instead of it, i want to calculate the time interval betweeen two date and the date i have in type string. Besides, i want to calculate seconds, minutes, hours too. How can i do this..?
Regards,
VELU
Blockquote
After some googling i have got this way to do so. Finally it works.
Blockquote
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date endDate = null;
try {
endDate = formatter.parse(tochangeDate);
} catch (ParseException e) {
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = null;
String curentDateandTime = sdf.format(new Date());
try {
startDate = formatter.parse(curentDateandTime);
} catch (ParseException e) {
}
long diff = (startDate.getTime()) - (endDate.getTime());
int numOfDays = (int) (diff / (1000 * 60 * 60 * 24));
int hours = (int) (diff / (1000 * 60 * 60));
int minutes = (int) (diff / (1000 * 60));
int seconds = (int) (diff / (1000));
This is what i have done and it works charm
I have written this quickly in a long winded way because I already had the library procedures to hand.