DateTimeFormatter的使用

package date;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class DateTimeFormatterTest {

    /**
     * 日期格式化
     * @param args
     */
    public static void main(String[] args) {

        LocalDateTime rightNow=LocalDateTime.now();
        String date=DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(rightNow);
        System.out.println(date);
        
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss");
        System.out.println(formatter.format(rightNow));
    }

}

你可能感兴趣的:(java)