日期工具类TimeUnit

1   import  java.util.concurrent.TimeUnit;
 2  
 3   public   class  TimeUnitDemo {
 4        private  TimeUnit timeUnit  = TimeUnit.DAYS;
 5  
 6        public   static   void  main(String[] args) {
 7           TimeUnitDemo demo  =   new  TimeUnitDemo();
 8           demo.outInfo();
 9           demo.timeUnit  = TimeUnit.HOURS;
10           demo.outInfo();
11           demo.timeUnit  = TimeUnit.MINUTES;
12           demo.outInfo();
13           demo.timeUnit  = TimeUnit.SECONDS;
14           demo.outInfo();
15       }
16  
17        public   void  outInfo() {
18           System.out.println(timeUnit.name());
19           System.out.println(timeUnit.toDays( 1 ));
20           System.out.println(timeUnit.toHours( 1 ));
21           System.out.println(timeUnit.toMinutes( 1 ));
22           System.out.println(timeUnit.toMicros( 1 ));
23           System.out.println(timeUnit.toMillis( 1 ));
24           System.out.println(timeUnit.toNanos( 1 ));
25           System.out.println(timeUnit.toSeconds( 1 ));
26           System.out.println( " 1天有 " + (timeUnit.convert( 1 , TimeUnit.DAYS)) + timeUnit.name());
27           System.out.println( " 12小时 " + (timeUnit.convert( 12 , TimeUnit.HOURS)) + timeUnit.name());
28           System.out.println( " 3600秒有 " + (timeUnit.convert( 36000 , TimeUnit.MINUTES)) + timeUnit.name());
29           System.out.println( " ------------------- " );
30       }
31   }

32 


--------------------------
DAYS
1
24
1440
86400000000
86400000
86400000000000
86400
1天有1DAYS
24小时0DAYS
3600秒有25DAYS
-------------------
HOURS
0
1
60
3600000000
3600000
3600000000000
3600
1天有24HOURS
24小时12HOURS
3600秒有600HOURS
-------------------
MINUTES
0
0
1
60000000
60000
60000000000
60
1天有1440MINUTES
24小时720MINUTES
3600秒有36000MINUTES
-------------------
SECONDS
0
0
0
1000000
1000
1000000000
1
1天有86400SECONDS
24小时43200SECONDS
3600秒有2160000SECONDS
-------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值