• 获取剩余的秒数


    一、maven配置

    <dependency>
          <groupId>joda-time</groupId>
          <artifactId>joda-time</artifactId>
          <version>2.9.9</version>
    </dependency>

    二、工具类

    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());
        }
    }
  • 相关阅读:
    HDU 4864 Task(经典贪心)
    51Nod
    POJ 3122 Pie(二分+贪心)
    HDU 1053 Entropy(哈夫曼编码 贪心+优先队列)
    POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
    11572
    HDU 1789 Doing Homework again(非常经典的贪心)
    合并果子(贪心+优先队列)
    CSU-ACM2018暑假集训6—BFS
    HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
  • 原文地址:https://www.cnblogs.com/muyl/p/7298512.html
Copyright © 2020-2023  润新知