给定格式:
2017-03-08 13:27:00
我想把它分成2个字符串 1表示日期,1表示时间 对
E.g。
08-03-2017
13:27:00
答案 0 :(得分:3)
首先,如果你的日期是String格式,那么将它解析为Date,然后尝试。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date today = new Date();
DateFormat timeFormat = SimpleDateFormat.getTimeInstance();
DateFormat dateFormat = SimpleDateFormat.getDateInstance();
timeFormat.format(today);
dateFormat.format(today);
System.out.println("Time: " + timeFormat.format(today));
System.out.println("Date: " + dateFormat.format(today));
}
}
<强>输出:强>
Time: 1:25:31 AM
Date: 31 Mar, 2017
希望这有帮助!
答案 1 :(得分:1)
试试这个
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FormateDate {
public static void main(String[] args) throws ParseException {
String date_s = "2017-03-08 13:27:00";
// *** note that it's "yyyy-MM-dd hh:mm:ss" not "yyyy-mm-dd hh:mm:ss"
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = dt.parse(date_s);
// *** same for the format String below
SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("Date :"+dt1.format(date));
dt1 = new SimpleDateFormat("HH:mm:ss");
System.out.println("Time :"+dt1.format(date));
}
}
它提供这样的输出
日期:2017-03-08时间:13:27:00
答案 2 :(得分:0)
试试这个:
listview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view,
int scrollState) {
if (scrollState == 0) {
InputMethodManager inputMethodManger = (InputMethodManager) getActivity().getSystemService(Activity
.INPUT_METHOD_SERVICE);
inputMethodManger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});