Java 如何在android中以YYYY-MM-DD HH:MI:Sec.毫秒格式获取当前时间
下面的代码给出了当前时间。但它并没有告诉任何关于毫秒的事情Java 如何在android中以YYYY-MM-DD HH:MI:Sec.毫秒格式获取当前时间,java,android,Java,Android,下面的代码给出了当前时间。但它并没有告诉任何关于毫秒的事情 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
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;
}
使用
'S'
获取毫秒
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;
}
使用此代码我希望这将对您有所帮助
String strDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(Calendar.getInstance().getTime());
试试这个:
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;
}
试试这个代码
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");