java時間操作

裸奔到月球發表於2024-03-11
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));**/

    }

相關文章