java时间操作

public static void main(String[] args) {
        LocalDateTime time = LocalDateTime.of(2022,11,30,6,6,6);
        DateTimeFormatter of = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime = time.format(of);
        System.out.println(dateTime); //

        Date date = new Date(2022,10,30,6,6,6);
        SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf4.format(date));


        Calendar calendar = Calendar.getInstance();
        calendar.set(2022,10,30,6,6,6);
        System.out.println(sdf4.format(calendar.getTime()));

        /**LocalDateTime now =LocalDateTime.now();
        DateTimeFormatter of = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateTime = now.format(of);
        System.out.println(dateTime); //

        Calendar calendar = Calendar.getInstance();
        Date d = calendar.getTime();
        //calendar.set(2022,10,30,6,6,6);
        SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy年MM月dd日  HH时mm分ss秒");
        System.out.println(sdf4.format(d));


        Date date = new Date();
        System.out.println(sdf4.format(date));**/

    }

 

posted @ 2024-03-11 10:03  裸奔到月球  阅读(3)  评论(0编辑  收藏  举报