【发布时间】:2016-09-17 14:46:54
【问题描述】:
我把这个日期和时间连接成一个字符串,我做对了吗?因为我想将 strDateTime 传递给 Long 类型(因为它的构造函数是 Long) 这是代码
public void DT(){
seldate = (TextView) findViewById(R.id.receivedate);
newDate = seldate.getText().toString();
timeChose = time1.getText().toString();
final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
strDateTime = newDate + " "+ timeChose ;
DatabaseSource sched = new DatabaseSource(
subject.getText().toString(),
description.getText().toString(),
strDateTime.toLong()
);
long result = dbHelper.addSched(sched);
if(result>0){
Toast.makeText(getApplicationContext(),"Added", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(),"Add Failed", Toast.LENGTH_SHORT).show();
}
}
P.S 选择的日期,我将其保存到首选项键,然后获取它并传递到下一个活动中的文本视图(我将在其中创建事件)然后单击 timepickerdialog 时我有一个编辑文本的时间弹出然后设置编辑文本字段本身的时间。
【问题讨论】:
-
strDateTime的格式是什么? -
字符串 strDateTime
-
我的意思是它是像
17-09-2016这样的格式吗?显示示例日期。 -
哦,是的,(yyyy-MM-dd)
-
你需要将时间戳传递给函数吗?