Reputation:
i am implementing custom listview in android with image, text and date but when i call getDate method it will work but return 1/1/1970 instead of showing my system date?
Upvotes: 0
Views: 688
Reputation:
you can try this
DateFormat date = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
Log.i("Log", "date is: "+date.format(new Date()));
date.format(new Date());
Upvotes: 1
Reputation: 6604
here is the complete solution.where you can get the date and also access it in the form of string.
private final static String getDateTime() {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
Log.i("Log", "date is: "+df.format(new Date()));
return df.format(new Date());
}
Upvotes: 1
Reputation: 4356
Use this:
Calendar c = Calendar.getInstance();
int seconds = c.get(Calendar.SECOND)
android calender documentation
Upvotes: 1
Reputation: 4307
You can just use new java.util.Date()
and it will contain the actual date. You can also use Calendar.getInstance()
or long time = System.currentTimeMillis(); new Date(time);
Upvotes: 2
Reputation: 128428
FYI, getDate() => This method is deprecated. And it returns the day of the month.
You can use:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // you can mention any format which you want
String currentDateandTime = sdf.format(new Date());
Upvotes: 2
Reputation: 24012
use this:
long dtMili = System.currentTimeMillis();
String date = new java.text.SimpleDateFormat("dd-MM-yy").format(new java.util.Date(dtMili));
Upvotes: 0