与时间相关的java源码_Java 基于当前时间获取和计算时间
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
/**來自
N o w J a v a . c o m - 時代Java**/
public class Main {
public static void main(String[] args){
LocalTime time = LocalTime.now();
System.out.println("Current Time: " + time);
// atDate(LocalDate): obtain the local date and time
LocalDateTime ldt = time.atDate(LocalDate.of(2011,Month.NOVEMBER,11));
System.out.println("Local Date Time object: " + ldt);
// of(int hours, int min): obtain a specific time
LocalTime pastTime = LocalTime.of(1, 10);
// compareTo(LocalTime): compare two times. Positive
// return value returned if greater
System.out.println("Comparing times: " + time.compareTo(pastTime));/** NowJava.com - 時 代 Java 提 供 **/
// getHour(): return hour in int value (24-hour format)
int hour = time.getHour();
int min = time.getMinute();
int nano = time.getNano();
int sec = time.getSecond();
System.out.println("Hour: " + hour);
// isAfter(LocalTime): return Boolean comparison
System.out.println("Is local time after pastTime? " + time.isAfter(pastTime));
// minusHours(int): Subtract Hours from LocalTime
LocalTime minusHrs = time.minusHours(5);
/**代碼未完, 請加載全部代碼(NowJava.com).**/
總結
以上是生活随笔為你收集整理的与时间相关的java源码_Java 基于当前时间获取和计算时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 金坛区实验幼儿园服务器不稳定,2019年
- 下一篇: rabbitmq 持久化_RabbitM