date, Calendar

Posted lijins

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了date, Calendar相关的知识,希望对你有一定的参考价值。

    Date date = new Date();
        System.out.println(date.toString());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");    
        System.out.println(format.format(date));
        
        
        String input = "1818-11-11 23:12:34";
        
        SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
//            System.out.println(f1.parse(input));
            Date date2 = f1.parse(input);
            
            System.out.println(date2);
        } catch (ParseException e) {
            
            e.printStackTrace();
        }
        
        
        Calendar calendar  = Calendar.getInstance();
        calendar.set(2019, 9, 12);
        
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONDAY));
        System.out.println(calendar.get(Calendar.DATE));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        
        calendar.add(Calendar.DATE, 30);
        
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONDAY));
        System.out.println(calendar.get(Calendar.DATE));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        

 

以上是关于date, Calendar的主要内容,如果未能解决你的问题,请参考以下文章

Date String Calendar之间的转换

Date类和Calendar类应用到计算活了多少天和判断闰年与平年

求java Date类型字段加一天代码

Calendar的日常应用

Date和Calendar

Calendar代替Date常用方法小记