Date与LocalDate,LocalDateTime,LocalTime的转换

package date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateConvertToLocalDate {

    /**
     * 
     * @param args
     */
    public static void main(String[] args) {

        Date date=new Date();
        LocalDate localDate=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDateTime localDateTime=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        System.out.println(localDate);
        System.out.println(localDateTime);
        System.out.println(date);
        
        LocalDateTime localDateTime1=LocalDateTime.now();
        ZonedDateTime zoneDateTime=ZonedDateTime.now();
        
        
        Date rightNow=Date.from(zoneDateTime.toInstant());
        System.out.println(rightNow);
        
    }

}

你可能感兴趣的:(java)