|
@@ -7,6 +7,13 @@ import java.util.Date;
|
|
|
|
|
|
public class DateUtil {
|
|
|
public static final String DATE_FORMAT_YMD = "yyyy-MM-dd";
|
|
|
+
|
|
|
+ private static final String[] WEEK_DAYS = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
|
|
+
|
|
|
+ private static final String[] WEEK_DAYS_SHORT = {"日", "一", "二", "三", "四", "五", "六"};
|
|
|
+
|
|
|
+ private static final String[] WEEK_DAYS_MIDDLE = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
|
|
+
|
|
|
/**
|
|
|
* 将时间戳转换成日期字符串格式
|
|
|
* @param timestamp 时间戳
|
|
@@ -71,4 +78,48 @@ public class DateUtil {
|
|
|
public static Date stringToDate(String strDate) {
|
|
|
return stringToDate(strDate, "yyyy-MM-dd HH:mm:ss");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static String convertToString(Date date){
|
|
|
+ return convertToString(date, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前日期是星期几
|
|
|
+ * @param calendar
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getDayOfWeek(Calendar calendar) {
|
|
|
+ int index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
|
|
+ if (index < 0) {
|
|
|
+ index = 0;
|
|
|
+ }
|
|
|
+ return WEEK_DAYS[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前日期是星期(缩略)
|
|
|
+ * @param calendar
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getDayOfWeekShort(Calendar calendar) {
|
|
|
+ int index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
|
|
+ if (index < 0) {
|
|
|
+ index = 0;
|
|
|
+ }
|
|
|
+ return WEEK_DAYS_SHORT[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前日期是星期(缩略)
|
|
|
+ * @param calendar
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getDayOfWeekMiddle(Calendar calendar) {
|
|
|
+ int index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
|
|
+ if (index < 0) {
|
|
|
+ index = 0;
|
|
|
+ }
|
|
|
+ return WEEK_DAYS_MIDDLE[index];
|
|
|
+ }
|
|
|
}
|