Java 程序从时钟创建 LocalDateTime
首先,设置时钟
Clock clock = Clock.systemUTC();
现在,创建 LocalDateTime
LocalDateTime dateTime = LocalDateTime.now(clock);
示例
import java.time.Clock; import java.time.LocalDateTime; public class Demo { public static void main(String[] args) { Clock clock = Clock.systemUTC(); System.out.println("Clock = "+Clock.systemDefaultZone()); LocalDateTime dateTime = LocalDateTime.now(clock); System.out.println("LocalDateTime = "+dateTime); } }
输出
Clock = SystemClock[Asia/Calcutta] LocalDateTime = 2019-04-19T09:29:50.605820900
广告