0

I know I can get the date from a datepicker using the following methods:

  • datepicker1.getDayOfMonth()
  • datepicker2.getMonth()
  • datepicker3.getYear()

I am also getting the time from a timepicker using the following methods:

  • timepicker1.getCurrentHour()
  • timepicker2.getCurrentMinute()

I need to format this data into "yyyy-MM-dd HH:mm:ss" format to place it into an sqlite database as a DATETIME variable. Is there a method which can handle this?

I think I will have to build it manually like so:

if(month < 10){
    month = "0" + month;
}
if(day < 10){
    day  = "0" + day ;
}

The problem was that the months and days were single digit.

4

3 に答える 3

1
SimpleDateFormat outputFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");

Date ModifiedDate  = outputFormat.parse(strdate);
于 2013-03-05T08:56:33.357 に答える
0

次の方法で現在の日付を取得し、文字列に保存できます

String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());

次に、この文字列をSimpledateformatクラスに渡し、次のように目的の形式を定義します。

 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateandTime = sdf.format(mydate);
于 2013-03-05T09:02:03.283 に答える
0

以下のように簡単です:

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.parse(yourDateHere);
于 2013-03-05T08:54:07.147 に答える