欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取年份、月份等

程序员文章站 2022-06-07 12:33:56
...
package com.zxj.time;

import java.util.Calendar;

public class Main3 {

	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_WEEK);
		int doy = cal.get(Calendar.DAY_OF_YEAR);
		System.out.println("当前时间:"+cal.getTime());
		System.out.println("日期:"+day);
		System.out.println("月份:"+month);
		System.out.println("年份:"+year);
		System.out.println("一周的第几天"+dow);
		System.out.println("一月的第几天:"+dom);
		System.out.println("一年的第几天:"+doy);
	}
}

相关标签: Java