1. 程式人生 > >獲取剩余的秒數

獲取剩余的秒數

second seconds 工具類 cti span with nbsp style user

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()); } }

獲取剩余的秒數