gpt4 book ai didi

Android:时间戳显示

转载 作者:行者123 更新时间:2023-11-30 04:26:23 26 4
gpt4 key购买 nike

我有一个问题,我想在我的数据库中插入时间戳。每次用户点击发送按钮时,显示的时间戳应该是用户点击按钮的时间。我这里有代码:

btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = editTextRecipient.getText().toString();
String message = editTextNewMessage.getText().toString();
Log.d(phoneNo, message);
saveState(phoneNo, message, details);
boolean split = false;

SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String date = s.format(new Date());

/*Bundle bundle = new Bundle();

bundle.putString(MessagesDBAdapter.KEY_RECIPIENT, editTextRecipient.getText().toString());
bundle.putString(MessagesDBAdapter.KEY_MESSAGE, editTextNewMessage.getText().toString());
bundle.putString(MessagesDBAdapter.KEY_DETAILS, tv_details.getText().toString());
if (mRowId != null) {
bundle.putLong(MessagesDBAdapter.KEY_ROWID, mRowId);
}*/

final Toast toast = Toast.makeText(getBaseContext(),
"Your message " + "\"" + message + "\"" + " is sent to " +"\""+ phoneNo+"\"",
Toast.LENGTH_SHORT);

Runnable showToastRunnable = new Runnable() {
public void run() {
dialog.cancel();
toast.show();
}
};

if (phoneNo.length()>0 && message.length()>0) {
showProgress();
if (count == 0) {
handler.postDelayed(showToastRunnable, 0);
}
else if (count == 1) {
handler.postDelayed(showToastRunnable, 15000);
}
else if (count == 2) {
handler.postDelayed(showToastRunnable, 30000);
}
else if (count == 3) {
handler.postDelayed(showToastRunnable, 60000);
}
}

// sendSMS(phoneNo, message, split); */
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
mDbHelper.close();
}

private void populateFields() {
if (mRowId!=null) {
Cursor message=mDbHelper.fetchNote(mRowId);
startManagingCursor(message);
editTextRecipient.setText(message.getString(message.getColumnIndexOrThrow(MessagesDBAdapter.KEY_RECIPIENT)));
editTextNewMessage.setText(message.getString(message.getColumnIndexOrThrow(MessagesDBAdapter.KEY_MESSAGE)));
tv_details.setText(message.getString(message.getColumnIndexOrThrow(MessagesDBAdapter.KEY_DETAILS)));
}
}

private void saveState(String phoneNo, String message, String details) {
Log.i(phoneNo, message);

if (mRowId==null) {
mDbHelper.createNote(phoneNo, message, details);
}
}

时间戳应以 24 小时制显示(12:30 等)。我这样做对吗,我错过了什么吗?谁能帮帮我?

最佳答案

您可以使用 Calendar类(class)。

Calendar now = Calendar.getInstance();
final int hour = now.get(Calendar.HOUR_OF_DAY);
final int minute = now.get(Calendar.MINUTE);

关于Android:时间戳显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com