赞
踩
用Calendar中方法来获取
- java 获取当前年份 月份 日期
- import java.util.Calendar;
-
- public class Main {
- public static void main(String[] args) {
- Calendar cal = Calendar.getInstance();//获取当前时间
- int day = cal.get(Calendar.DATE);//获取当前日
- int month = cal.get(Calendar.MONTH) + 1;//获取当前月份
- int year = cal.get(Calendar.YEAR);//获取当前年份
- int dow = cal.get(Calendar.DAY_OF_WEEK);
- int dom = cal.get(Calendar.DAY_OF_MONTH);
- int doy = cal.get(Calendar.DAY_OF_YEAR);
-
- System.out.println("Current Date: " + cal.getTime());
- System.out.println("Day: " + day);
- System.out.println("Month: " + month);
- System.out.println("Year: " + year);
- System.out.println("Day of Week: " + dow);
- System.out.println("Day of Month: " + dom);
- System.out.println("Day of Year: " + doy);
- }
- }
参考:
Calendar类的使用/Calendar.add/Calendar.set等使用/Calendar加一天_calendar 加一天-CSDN博客
Java正确获取星期Calendar.DAY_OF_WEEK_calendar.get(calendar.day_of_week)_zzhongcy的博客-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。