user1543629
user1543629

Reputation:

getDate() does not return the exact date that system have?

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

Answers (6)

user1087919
user1087919

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

Narendra Pal
Narendra Pal

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

Zaz Gmy
Zaz Gmy

Reputation: 4356

Use this:

Calendar c = Calendar.getInstance(); 
int seconds = c.get(Calendar.SECOND)

android calender documentation

Upvotes: 1

Adam Monos
Adam Monos

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

Paresh Mayani
Paresh Mayani

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

Archie.bpgc
Archie.bpgc

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

Related Questions