Java用のJodaDateTime関数を使用して、設定した時間に30分を追加しています。たとえば、10:00:00から10:30:00まで。ただし、以下のコードは機能していません。主な2つの問題は
1です。年が2012に設定されると、myFormat.parse関数は自動的に日付を2014に設定します(以下のlogcatを参照)。2. plusMinutes(30)は時間に30分を追加していません。私のコードを調べて、修正方法を教えてもらえますか?
Javaコード:
package com.google.android.gcm.demo.app.Alerts;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.joda.time.DateTime;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.google.android.gcm.demo.app.R;
import com.google.android.gcm.demo.app.EventList.DataView;
import com.google.android.gcm.demo.app.EventList.EventDetails;
import com.google.android.gcm.demo.app.sqllite.DatabaseSqlite;
public class AlertDetails extends Activity {
Integer id;
String name;
String date;
String startTime;
String endTime;
String location;
int alertState;
Bundle bundle;
String alertTime;
String s;
private String update_alarmTime;
String eventYear;
String eventDay;
String eventMonth;
DatabaseSqlite entry = new DatabaseSqlite(AlertDetails.this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alertview);
bundle = getIntent().getExtras();
alertTime = bundle.getString("alertTime");
alertTime = "10:00:00";// for testing
// set Date
eventYear = date.substring(0, 4);
eventDay = date.substring(5, 7);
eventMonth = date.substring(8, 10);
mDateDisplay.setText(eventDay + "-" + eventMonth + "-" + eventYear);
String eventdate = eventDay + "/" + eventMonth + "/" + eventYear;
System.out.println("event date "+eventdate);
String currentDate;
SimpleDateFormat myFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date1 = null;
DateTime dt;
currentDate = eventdate+ " "+alertTime;
System.out.println("current date "+currentDate);
try {
date1 = myFormat.parse(currentDate);
System.out.println("date formated: "+date1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dt = new DateTime(date1);
dt.plusMinutes(30);
System.out.println(" origional time is " +alertTime+" new time is "+dt);
Logcat:
02:43:16.844: D/dalvikvm(1027): GC_FOR_MALLOC freed 2421 objects / 165200 bytes in 137ms
08-09 02:43:18.355: I/ActivityManager(58): Starting activity: Intent { cmp=com.google.android.gcm.demo.app/.Alerts.AlertDetails (has extras) }
08-09 02:43:18.405: I/System.out(1027): event date 05/30/2012
08-09 02:43:18.415: I/System.out(1027): current date 05/30/2012 10:00:00
08-09 02:43:18.415: I/System.out(1027): date formated: Thu Jun 05 10:00:00 GMT+00:00 2014
08-09 02:43:18.605: D/dalvikvm(1027): GC_FOR_MALLOC freed 2743 objects / 261528 bytes in 43ms
08-09 02:43:18.665: D/dalvikvm(1027): GC_FOR_MALLOC freed 216 objects / 242000 bytes in 43ms
08-09 02:43:18.905: D/dalvikvm(1027): GC_FOR_MALLOC freed 1461 objects / 314440 bytes in 45ms
08-09 02:43:19.305: D/dalvikvm(1027): GC_FOR_MALLOC freed 3043 objects / 276440 bytes in 55ms
08-09 02:43:19.945: D/dalvikvm(1027): GC_FOR_MALLOC freed 5365 objects / 354056 bytes in 54ms
08-09 02:43:19.955: I/System.out(1027): origional time is 10:00:00 new time is 2014-06-05T10:00:00.000Z