java裏獲取當前時間戳超級方便,System.currentTimeMillis();一行代碼搞定,C++怎麼獲取呢?看下面:
#include <ctime>
JNIEXPORT jlong JNICALL Java_com_ygc_demo_jni_ApiNative_timeTest
(JNIEnv *env, jclass jc){
time_t now = time(0);
long long currentTime = ((long long)now)*1000;
LOGE("currentTime=%lld",currentTime);
return currentTime;
}
//JNI原型
public native static long timeTest();
long result6 = ApiNative.timeTest();
String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(result6));
Log.d("TAG",dateStr);
上報給java層後格式化自己想要的格式。