获取剩余的秒数
Posted 嘟嘟的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取剩余的秒数相关的知识,希望对你有一定的参考价值。
1.maven配置
<dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.9.9</version> </dependency>
2.工具类
package com.hk; import org.joda.time.DateTime; import org.joda.time.Minutes; import org.joda.time.Seconds; /** * User: hk * Date: 2017/8/7 上午11:24 * version: 1.0 */ public final class DateKit { /** * 获取今天剩余的秒数 * * @return 秒数 */ public static int oddSecondOfDay() { DateTime start = new DateTime(); DateTime end = new DateTime().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return Seconds.secondsBetween(start, end).getSeconds(); } /** * 获取本周剩余的秒数 * * @return 秒数 */ public static int oddSecondOfWeek() { DateTime start = new DateTime(); DateTime end = new DateTime().dayOfWeek().withMaximumValue().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return Seconds.secondsBetween(start, end).getSeconds(); } /** * 获取本月剩余的秒数 * * @return 秒数 */ public static int oddSecondOfMonth() { DateTime start = new DateTime(); DateTime end = new DateTime().dayOfMonth().withMaximumValue().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return Seconds.secondsBetween(start, end).getSeconds(); } /** * 获取今年剩余的秒数 * * @return 秒数 */ public static int oddSecondOfYear() { DateTime start = new DateTime(); DateTime end = new DateTime().dayOfYear().withMaximumValue().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return Seconds.secondsBetween(start, end).getSeconds(); } public static void main(String[] args) { System.out.println(oddSecondOfDay()); System.out.println(oddSecondOfWeek()); System.out.println(oddSecondOfMonth()); System.out.println(oddSecondOfYear()); } }
以上是关于获取剩余的秒数的主要内容,如果未能解决你的问题,请参考以下文章