当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to make a String From 2 others in one line?

问题描述:

I have in my app activity two textviews one with date("yyyy-mm-dd ") and one with time("hh:mm")

How can i make a string that combines these textviews together so my String will be (yyyy-mm-dd hh:mm) so that i can sort datetime text values in my sqlite database.

code for date textview:

String date = ((TextView) findViewById(R.id.dateTV))

.getText().toString();

code for time textview:

String time= ((TextView) findViewById(R.id.timeTV))

.getText().toString();

How to make String datetime tha combines them in one line/fast?

网友答案:

Concatenate with a plus-sign

  String datetime = ((TextView) findViewById(R.id.dateTV)).getText().toString() + ((TextView) findViewById(R.id.timeTV)).getText().toString();
网友答案:
String date = ((TextView) findViewById(R.id.dateTV)).getText().toString();
String time = ((TextView) findViewById(R.id.timeTV)).getText().toString();

String combined = date + " " + time;

Lookup string concatenation.

网友答案:
new StringBuilder().append(date).append(" ").append(time).toString();

This, in theory, faster/better than concatenating strings with +. Although you won't see the difference.

网友答案:

Use this

 String date = ((TextView) findViewById(R.id.dateTV))
        .getText().toString();

 String time= ((TextView) findViewById(R.id.timeTV))
        .getText().toString();

String datetime = date.concat(time);
网友答案:

I guess you can use Calendar.set()

 public final void set(int year,
                  int month,
                  int date,
                  int hourOfDay,
                  int minute)
网友答案:
String dateAndTime = date + time;

Is it really this you wan't?

网友答案:

Use string concatenation

String newDate = date + " " + time;
分享给朋友:
您可能感兴趣的文章:
随机阅读: