java:时区
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
public class Driver {
public static void main(String[] args) {
//获取系统剩余的内存空间
long begin1 = Runtime.getRuntime().freeMemory();
//获取系统的当前时间
long start01 = System.currentTimeMillis();
/**
* ZonedDateTime=LocalDateTime+Zoneld
* ·ZonedDateTime:带时区的日期和时间
* ·ZoneId:新的时区对象(取代旧的java.util.TimeZone)
* ·Instant:时刻对象(epoch seconds)
*/
ZonedDateTime zonedDateTime=ZonedDateTime.now();//当前时区的日期和时间
System.out.println(zonedDateTime);
ZonedDateTime zonedDateTime1=ZonedDateTime.now(ZoneId.of("America/New_York"));
System.out.println(zonedDateTime1);
// 关联到当前默认时区:
LocalDateTime localDateTime=LocalDateTime.of(2019,05,06,10,37,57);
ZonedDateTime zonedDateTime2=localDateTime.atZone(ZoneId.systemDefault());
System.out.println(zonedDateTime2);
//转换到纽约时区:
ZonedDateTime zonedDateTime3=zonedDateTime2.withZoneSameInstant(ZoneId.of("America/New_York"));
System.out.println(zonedDateTime3);
System.out.println("\t\t");
//获取系统剩余的内存空间
long end2 = Runtime.getRuntime().freeMemory();
//获取系统的当前时间 单位是毫秒
long finish02 = System.currentTimeMillis();
System.out.println("本程序占用内存:" + (begin1 - end2));
System.out.println("本程序占用时间:" + (finish02 - start01));
}
}
posted on 2019-05-06 13:43 Indian_Mysore 阅读(131) 评论(0) 编辑 收藏 举报