posts - 495,comments - 227,trackbacks - 0
方法一、
 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 "";
   }
  }



方法二、

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]);
 }
}

posted on 2006-12-08 13:25 SIMONE 阅读(7351) 评论(0)  编辑  收藏 所属分类: JAVAJSP

只有注册用户登录后才能发表评论。


网站导航: