java 获取当前时间的年份、月份、周数


 

java 获取当前时间的年份、月份、周数

import java.text.SimpleDateFormat;
import java.util.Calendar;
public class testCal {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        String getCurrentTime=new SimpleDateFormat("yyyy-MM-dd ").format(c.getTime());
        System.out.println(getCurrentTime);//年-月-日
        String getCurrent1=new SimpleDateFormat("yyyy-MM ").format(c.getTime());
        System.out.println(getCurrent1);//年-月
        System.out.println("当前时间 年-月-日:" + new SimpleDateFormat("yyyy-MM-dd ").format(c.getTime()));
        System.out.println("当前时间 年-月-日 时:分:秒:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime()));
        System.out.println("当前时间的年份:" + c.get(Calendar.YEAR));//获取当前年
        System.out.println("当前时间的月份:" + (c.get(Calendar.MONTH) + 1));
        // 一年内的第xx周//获取当前星期是第几周
        System.out.println("当前时间的年周数:" + c.get(Calendar.WEEK_OF_YEAR));
}
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM