JAVA 的data类型 long类型 生成星期几汇总

**
*
* 时间的操作类
*
* */
public class TimeUtil {

/**
* 返回系统时间
*
* @param void
* @return 系统时间 long
*
* */
public static long CurrentTime() {

return System.currentTimeMillis();

}

/**
* 返回年-月-日 hh:ff:ss
*
* @param time
* long系统时间的long类型
* @return String yyyy-MM-dd HH:mm:ss类型的时间类型
* */
public static String getFormatTime(long time) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = new Date(time);

String formatTime = format.format(date);

return formatTime;

}

/**
* 星期几
*
* @param data
* Date 日期
* @return 星期一到星期日
*
* */
public static String getWeekOfDate(Date date) {
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;

return weekDays[w];
}

/**
* 星期几
*
* @param time
* long 系统时间的long类型
* @return 星期一到星期日
*
* */
public static String getWeekOfDate(long time) {

Date date = new Date(time);
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;

return weekDays[w];
}

/**
* 返回年-月-日 hh:ff:ss 星期几
*
* @param time
* long系统时间
* @return String 例如2013-05-26 19:39:26 星期日
*
* */

public static String getDateAndWeek(long time) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = new Date(time);

String dateString = format.format(date);

String dayString = getWeekOfDate(date);

return dateString + " " + dayString;

}

}

posted @ 2013-05-26 20:06  qgweizhan  阅读(1393)  评论(0编辑  收藏  举报