jsp怎么获取当月第一天和最后一天
答案:3 悬赏:30 手机版
解决时间 2021-01-25 19:43
- 提问者网友:不要迷恋哥
- 2021-01-25 16:20
jsp怎么获取当月第一天和最后一天
最佳答案
- 五星知识达人网友:一秋
- 2021-01-25 17:15
[java] view plain copy
public class CalendarTest {
public static void main(String[] args) {
// 获取当前年份、月份、日期
Calendar cale = null;
cale = Calendar.getInstance();
int year = cale.get(Calendar.YEAR);
int month = cale.get(Calendar.MONTH) + 1;
int day = cale.get(Calendar.DATE);
int hour = cale.get(Calendar.HOUR_OF_DAY);
int minute = cale.get(Calendar.MINUTE);
int second = cale.get(Calendar.SECOND);
int dow = cale.get(Calendar.DAY_OF_WEEK);
int dom = cale.get(Calendar.DAY_OF_MONTH);
int doy = cale.get(Calendar.DAY_OF_YEAR);
System.out.println("Current Date: " + cale.getTime());
System.out.println("Year: " + year);
System.out.println("Month: " + month);
System.out.println("Day: " + day);
System.out.println("Hour: " + hour);
System.out.println("Minute: " + minute);
System.out.println("Second: " + second);
System.out.println("Day of Week: " + dow);
System.out.println("Day of Month: " + dom);
System.out.println("Day of Year: " + doy);
// 获取当月第一天和最后一天
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String firstday, lastday;
// 获取前月的第一天
cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 0);
cale.set(Calendar.DAY_OF_MONTH, 1);
firstday = format.format(cale.getTime());
// 获取前月的最后一天
cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 1);
cale.set(Calendar.DAY_OF_MONTH, 0);
lastday = format.format(cale.getTime());
System.out.println("本月第一天和最后一天分别是 : " + firstday + " and " + lastday);
// 获取当前日期字符串
Date d = new Date();
System.out.println("当前日期字符串1:" + format.format(d));
System.out.println("当前日期字符串2:" + year + "/" + month + "/" + day + " "
+ hour + ":" + minute + ":" + second);
}
}
public class CalendarTest {
public static void main(String[] args) {
// 获取当前年份、月份、日期
Calendar cale = null;
cale = Calendar.getInstance();
int year = cale.get(Calendar.YEAR);
int month = cale.get(Calendar.MONTH) + 1;
int day = cale.get(Calendar.DATE);
int hour = cale.get(Calendar.HOUR_OF_DAY);
int minute = cale.get(Calendar.MINUTE);
int second = cale.get(Calendar.SECOND);
int dow = cale.get(Calendar.DAY_OF_WEEK);
int dom = cale.get(Calendar.DAY_OF_MONTH);
int doy = cale.get(Calendar.DAY_OF_YEAR);
System.out.println("Current Date: " + cale.getTime());
System.out.println("Year: " + year);
System.out.println("Month: " + month);
System.out.println("Day: " + day);
System.out.println("Hour: " + hour);
System.out.println("Minute: " + minute);
System.out.println("Second: " + second);
System.out.println("Day of Week: " + dow);
System.out.println("Day of Month: " + dom);
System.out.println("Day of Year: " + doy);
// 获取当月第一天和最后一天
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String firstday, lastday;
// 获取前月的第一天
cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 0);
cale.set(Calendar.DAY_OF_MONTH, 1);
firstday = format.format(cale.getTime());
// 获取前月的最后一天
cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 1);
cale.set(Calendar.DAY_OF_MONTH, 0);
lastday = format.format(cale.getTime());
System.out.println("本月第一天和最后一天分别是 : " + firstday + " and " + lastday);
// 获取当前日期字符串
Date d = new Date();
System.out.println("当前日期字符串1:" + format.format(d));
System.out.println("当前日期字符串2:" + year + "/" + month + "/" + day + " "
+ hour + ":" + minute + ":" + second);
}
}
全部回答
- 1楼网友:拜訪者
- 2021-01-25 19:53
Calendar cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 0);
cale.set(Calendar.DAY_OF_MONTH, 1);
firstday = format.format(cale.getTime());
// 获取前月的最后一天
cale = Calendar.getInstance();
cale.add(Calendar.MONTH, 1);
cale.set(Calendar.DAY_OF_MONTH, 0);
lastday = format.format(cale.getTime());
System.out.println("本月第一天和最后一天分别是 : " + firstday + " and " + lastday);
- 2楼网友:低音帝王
- 2021-01-25 18:46
获取当月第一天及最后一天.
$begindate=date('y-m-01', strtotime(date("y-m-d")));
echo $begindate;
echo "
";
echo date('y-m-d', strtotime("$begindate +1 month -1 day"));
echo "
";
date(‘y-m-01’,time()) date('y-m-t',time());
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯