System.currentTimeMillis () throws incorrect android output

when i type System.currentTimeMillis()

give me:

11-03 14:47:05.400: INFO/System.out(7579): date is :: 14475410111

What is the correct procedure to get the full date with time.?

+5
source share
5 answers

To get the current date and time in Android, you can use:

Calendar c = Calendar.getInstance();
System.out.println("Current time => "+c.getTime());

Conclusion:

Current time => Thu Nov 03 15:00:45 GMT + 05: 30 2011

FYI, if you have this time in the 'c' object, you can use the SimpleDateFormat class to get the date / time in the desired format.

Final decision:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Sring formattedDate = df.format(c.getTime());     // c is Calendar object
System.out.println("========> formatted date => "+formattedDate);

Conclusion: ========> formatted date => 2011-11-03 15:13:37

+5
source
Date now = new Date(System.currentTimeMillis());

By the way: currentTimeMillis()

1 1970 00:00:00 UTC.

+3

Yes. This is the correct way to get the current time and date. that you need to convert it to the desired format.

public static String getDateFromTimeStamp(String timeStamp){
        return new Date(Long.parseLong(timeStamp)).toString();
    }
+2
source

Use the Date class .

(What makes you think this is wrong? You are asking for time in milliseconds.)

0
source
0
source

All Articles