方法一、
public static String getFullDateWeekTime(String sDate){
try{
String formater = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat format-dd HH:mm:ss";
SimpleDateFormat format = newpleDateFormat (formater);
Date date=format.parse(sDate);
format.applyPattern("yyyy-MM-dd E HH:mm:ss");
return formatmat.format(date);
}catch(Exception ex){
System.out.println("TimeUtil getFullDateWeekTime" ex.getMessage());
return "";
}
#[@more@]方法二、
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java .util.Date;
public class Test {
public static void main(String[] args) {
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
"星期六" };
String s = "2006-01-12 16:30";
SimpleDateFormat sdfInput = new SimpleDateFormat ("yyyy-MM-dd HH:mm");
Calendar calendar = Calendar.getInstance();
Date date = new Date();
try {
date = sdfInput.parse(s);
} catch (ParseException e) {
e.printStackTrace();
}
#calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1;
if(dayOfWeek<0)dayOfWeek=0;
System.out.println(dayNames[dayOfWeek]);
}
}
以上是java如何根據日期取得星期的詳細內容。更多資訊請關注PHP中文網其他相關文章!