找到关于编程的34423 篇文章
1K+ 次浏览
首先,显示当前日期:LocalDate date = LocalDate.now(); 现在,从上面的日期(当前日期)获取星期几:DayOfWeek day = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK)); 基于以上结果,使用SWITCH检查当前日期。如果日期是星期六/星期天,则为周末。示例import java.time.DayOfWeek; import java.time.temporal.ChronoField; import java.time.LocalDate; public class Demo { public static void main(String[] argv) { LocalDate date = LocalDate.now(); DayOfWeek day = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK)); switch (day) { case SATURDAY: System.out.println("Weekend - Saturday"); ... 阅读更多
894 次浏览
设置两个Java日期:LocalDate date1 = LocalDate.of(2019, 3, 25); LocalDate date2 = LocalDate.of(2019, 4, 29); 现在,使用Period类的between()方法获取两个日期之间的差值:Period p = Period.between(date1, date2); 现在,获取年、月和日:p.getYears() p.getMonths() p.getDays() 示例 import java.time.LocalDate; import java.time.Period; public class Demo { public static void main(String[] args) { LocalDate date1 = LocalDate.of(2019, 3, 25); LocalDate date2 = LocalDate.of(2019, 4, 29); System.out.println("Date 1 = "+date1); System.out.println("Date 2 = "+date2); Period p = Period.between(date1, date2); System.out.println("Period = "+p); ... 阅读更多
211 次浏览
让我们首先设置一个Instant:Instant now = Instant.ofEpochMilli(184142540078l); 现在让我们从Instant中减去秒:Instant resSeconds = now.minusSeconds(50); 现在让我们从Instant中减去纳秒:Instant resNanoSeconds = now.minusNanos(10000); 示例 import java.time.Instant; public class Demo { public static void main(String[] args) { Instant now = Instant.ofEpochMilli(184142540078l); System.out.println(now); Instant resSeconds = now.minusSeconds(50); System.out.println("After subtracting seconds = "+resSeconds); Instant resNanoSeconds = now.minusNanos(10000); System.out.println("After subtracting nanoseconds = "+resNanoSeconds); } } 输出 1975-11-02T06:42:20.078Z After subtracting seconds = 1975-11-02T06:41:30.078Z After subtracting nanoseconds = 1975-11-02T06:42:20.077990Z
3K+ 次浏览
以下是两个Instant时间戳:Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935); 获取两个Instant之间的Duration:Duration res = Duration.between(one, two); 现在,获取两个时间戳之间的秒数:long seconds = res.getSeconds(); 现在,获取两个时间戳之间的分钟数:long minutes = res.abs().toMinutes(); 示例 import java.time.Duration; import java.time.Instant; public class Demo { public static void main(String[] args) { Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935); Duration res = Duration.between(one, two); System.out.println(res); long seconds = res.getSeconds(); System.out.println("Seconds between Durations = "+seconds); ... 阅读更多
19K+ 次浏览
让我们首先使用ofEpochSeconds()方法设置两个Instant,使用自1970-01-01T00:00:00Z纪元以来的秒数。 现在获取上面两个Instant之间的持续时间:Duration res = Duration.between(one, two); 示例 import java.time.Duration; import java.time.Instant; public class Demo { public static void main(String[] args) { Instant one = Instant.ofEpochSecond(1845836728); Instant two = Instant.ofEpochSecond(1845866935); Duration res = Duration.between(one, two); System.out.println(res); } } 输出 PT8H23M27S
191 次浏览
创建一个Instant,并使用自1970-01-01T00:00:00Z纪元以来作为参数传递的毫秒数获取一个Instant。这是使用ofEpochMilli()完成的:Instant instant = Instant.ofEpochMilli(342627282920l); 现在,从Instant获取纪元毫秒:instant. toEpochMilli(); 示例 import java.time.Instant; public class Demo { public static void main(String[] args) { Instant instant = Instant.ofEpochMilli(1262347200000l); long res = instant.toEpochMilli(); System.out.println(res); } } 输出 1262347200000
193 次浏览
创建一个Instant,并使用自1970-01-01T00:00:00Z纪元以来作为参数传递的毫秒数获取一个Instant。这是使用ofEpochMilli()完成的:Instant instant = Instant.ofEpochMilli(342627282920l); 现在,从Instant获取纪元秒:instant.getEpochSecond(); 示例 import java.time.Instant; public class Demo { public static void main(String[] args) { Instant instant = Instant.ofEpochMilli(342627282920l); long res = instant.getEpochSecond(); System.out.println(res); } } 输出 342627282
1K+ 次浏览
从纪元秒创建Instant 示例 import java.time.Instant; public class Demo { public static void main(String[] args) { Instant instant = Instant.ofEpochSecond(282829279); System.out.println(instant); } } 输出 1978-12-18T11:41:19Z 从纪元毫秒创建Instant 示例 import java.time.Instant; public class Demo { public static void main(String[] args) { Instant instant = Instant.ofEpochMilli(272827282728l); System.out.println(instant); } } 输出 1978-08-24T17:21:22.728Z
123 次浏览
有了这个,我们可以得到天、小时和分钟的纳秒数。 首先,设置持续时间:Duration d1 = Duration.ofDays(5); Duration d2 = Duration.ofHours(20); Duration d3 = Duration.ofMinutes(15); 将上述持续时间转换为纳秒:System.out.println("Nanoseconds in 5 days = "+d1.toNanos()); System.out.println("Nanoseconds in 20 hours = "+d2.toNanos()); System.out.println("Nanoseconds in 15 minutes = "+d3.toNanos()); 示例 import java.time.Duration; public class Demo { public static void main(String[] args) { Duration d1 = Duration.ofDays(5); Duration d2 = Duration.ofHours(20); Duration d3 = Duration.ofMinutes(15); System.out.println("Nanoseconds in 5 days = "+d1.toNanos()); System.out.println("Nanoseconds in 20 hours = "+d2.toNanos()); ... 阅读更多
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP