ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

日历

2022-07-18 20:01:06  阅读:41  来源: 互联网

标签:日历 System SimpleDateFormat println calendar Calendar out


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {
        Date now = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String dataStr = simpleDateFormat.format(now);

        System.out.println("今天的日期是"+dataStr);
        System.out.println("今天的日期是"+now);


        Calendar calendar=Calendar.getInstance();
        System.out.println(calendar);
        System.out.println(calendar.getTime());
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH));//0是一月,少一个月
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));//星期天是第一天
        calendar.add(Calendar.MONTH,1);
        System.out.println("一个月后:"+calendar.getTime());
    }
}

 

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TestCalendar {
    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar calendar=Calendar.getInstance();
        calendar.set(2012,4,6);
        System.out.println(simpleDateFormat.format(calendar.getTime())+"是一年中的第"+calendar.get(Calendar.WEEK_OF_YEAR)+"星期");
    }
}

 

标签:日历,System,SimpleDateFormat,println,calendar,Calendar,out
来源: https://www.cnblogs.com/linlinmailbox/p/16491788.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有