gpt4 book ai didi

php - android mysql 在 TextView 中显示日期/时间

转载 作者:行者123 更新时间:2023-11-29 11:50:15 26 4
gpt4 key购买 nike

我正在尝试在 TextView 中显示当前日期/时间,我已成功显示日期但不知道如何显示时间,日期/时间的格式必须为“2015-12-10 01: 52:23',因为它将存储在数据库字段 TIMESTAMP 中。这是我到目前为止所拥有的(仅打印日期“2015-12-10”)

        displayDate = (TextView) findViewById(R.id.DATE);

final Calendar cal = Calendar.getInstance();
yy = cal.get(Calendar.YEAR);
mm = cal.get(Calendar.MONTH);
dd = cal.get(Calendar.DAY_OF_MONTH);

// set current date into textview
displayDate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(yy).append(" ").append("-").append(mm + 1).append("-")
.append(dd));

然后将其传递到此: 最终字符串日期时间 = displayDate.getText().toString().trim();

添加到数据库中:

            @Override
protected String doInBackground(Void... v) {
HashMap<String,String> params = new HashMap<>();
params.put(Config.KEY_EMP_ID, TextUserID);
params.put(Config.KEY_LAT,lat);
params.put(Config.KEY_LON,lon);

Config 是一个 java 文件,其中包含使用 php 查询数据库的键和 JSON 标签:

//Keys that will be used to send the request to php scripts
public static final String KEY_EMP_ID = "UserID";
public static final String KEY_LAT = "Latitude";
public static final String KEY_LON = "Longitude";
public static final String KEY_TIMEINSERTED = "TimeInserted";

最佳答案

我目前无法对此进行测试,但您可能需要考虑使用 SimpleDateFormat。

Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
displayDate.setText(dateFormat.format(calendar.getTime()));

您还应该考虑使用区域设置。

关于php - android mysql 在 TextView 中显示日期/时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34214975/

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