黑马程序员技术交流社区
标题:
Calendar学习,ps:最近进度有些慢
[打印本页]
作者:
noiary
时间:
2014-10-15 14:30
标题:
Calendar学习,ps:最近进度有些慢
本帖最后由 noiary 于 2014-10-15 14:31 编辑
转眼已经过了几个月,进度本来就不快,最近10.1更是龟速进行.
在尽量避免急功近利和拔苗助长的前提下,尽可能的提高学习效率.
up!
/*
Calendar学习
*/
import java.util.*;
import java.text.*;
public class CalendarDemo {
public static void main(String[] args) {
System.out.println("今天是:" + getDate(Calendar.getInstance()));
System.out.println("距离本周五还有" + getDifferenceDays(5) + "天.");
System.out.println("本周一的日期是:" + getDate(getThisMondayDate(1)));
System.out.println("上月最后一天是:" + getLastMonthEndDate());
}
/*获取指定Calendar的日期*/
public static String getDate(Calendar cal) {
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String strDate = sdf.format(date);
return strDate;
}
/*获取今天与本周x的相差天数*/
public static int getDifferenceDays(int dayOfWeekParam) {
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
int difDays = dayOfWeekParam - dayOfWeek;
return difDays;
}
/*获取本周X的日期*/
public static Calendar getThisMondayDate(int dayOfWeekParam) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) + getDifferenceDays(dayOfWeekParam));
return calendar;
}
/*获取上个月最后一天的日期*/
public static String getLastMonthEndDate() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 0);
return getDate(calendar);
}
/*查表发获取星期日期大写
private static String upperWeekDay(int weekDay) {
String[] weeksArray = {"一","二","三","四","五","六","日"};
return weeksArray[weekDay-1];
}
*/
}
复制代码
作者:
yangzhong1991
时间:
2014-10-15 15:18
我现在也是看到这里,今天开始看IO
作者:
郭.威
时间:
2014-10-16 01:26
比较难,不太会
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2