方法一、
public static String getFullDateWeekTime(String sDate){
try{
String formater = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat format = new SimpleDateFormat(formater);
Date date=format.parse(sDate);
format.applyPattern("yyyy-MM-dd E HH:mm:ss");
return format.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中文网其他相关文章!