0

The code below gives me the current time. But it does not tell anything about milliseconds.

public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}
MysticMagicϡ
  • 28,305
  • 16
  • 71
  • 119

5 Answers5

1
public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}
Sagar Pilkhwal
  • 5,914
  • 2
  • 27
  • 78
0

USe 'S' to get milliseconds

public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss S");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}
sol4me
  • 14,603
  • 5
  • 33
  • 32
0

use this code i hope this will be help to you

String strDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(Calendar.getInstance().getTime());
Android_coder
  • 9,743
  • 3
  • 16
  • 23
0

Try this:

 public static String getCurrentTimeStamp() {
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
     Date now = new Date();
     String strDate = sdfDate.format(now);
     return strDate; 
 }
Rikkert09
  • 190
  • 1
  • 1
  • 11
0

Try this code

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
MysticMagicϡ
  • 28,305
  • 16
  • 71
  • 119
siddhartha shankar
  • 1,360
  • 12
  • 15