Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.currentTimeMillis() give wrong output android

Tags:

android

when i am print System.currentTimeMillis()

give me :

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

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

like image 562
Nikunj Patel Avatar asked Nov 03 '11 09:11

Nikunj Patel


1 Answers

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

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

Output:

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

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

Final Solution:

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);

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

like image 138
Paresh Mayani Avatar answered Nov 04 '22 06:11

Paresh Mayani