码迷,mamicode.com
首页 > 其他好文 > 详细

获取剩余的秒数

时间:2017-08-07 13:49:36      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:imu   maven配置   seconds   ret   log   pid   ati   with   new   

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

 

获取剩余的秒数

标签:imu   maven配置   seconds   ret   log   pid   ati   with   new   

原文地址:http://www.cnblogs.com/muyl/p/7298512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!