下面的代碼可以通過當前的時間獲取當前的星期,怎麼改為輸入日期26/8/2013
這種格式得到星期的?
Calendar calender = Calendar.getInstance();
Log.d("Current Week:", "" + calender.get(Calendar.WEEK_OF_YEAR));
Toast.makeText(this, "current year weeks is"+ calender.get(Calendar.WEEK_OF_YEAR),
Toast.LENGTH_SHORT).show();
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import android.net.ParseException;
import android.widget.Toast;
...
Date date;
String dtStart = "26/8/2013"; // Input date from user
SimpleDateFormat format = new SimpleDateFormat("dd/M/yyyy");
try {
date = format.parse(dtStart);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Calendar calender = new GregorianCalendar();
calender.setTime(date);
Toast.makeText(this, "current year weeks is" + calender.get(Calendar.WEEK_OF_YEAR), Toast.LENGTH_SHORT).show();