java时间操作:获取当天剩余时间
mport org.apache.commons.lang.time.DateUtils;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Test; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar; /**
* Created by Administrator on 2016/12/12.
*/
public class TimeTest { @Test
public void getTime() { //方法一
long milliSecondsLeftToday = 86400000 - DateUtils.getFragmentInMilliseconds(Calendar.getInstance(), Calendar.DATE);
long secondsLeftToday = 86400 - DateUtils.getFragmentInSeconds(Calendar.getInstance(), Calendar.DATE);
System.out.println("当天剩余毫秒1:" + milliSecondsLeftToday);
System.out.println("当天剩余秒1:" + secondsLeftToday); //方法二
DateTime dateTime = new DateTime().millisOfDay().withMaximumValue();
long millSeconds2 = new Duration(new DateTime(), dateTime).getMillis();
long count = new Duration(new DateTime(), dateTime).getStandardSeconds();
System.out.println("当天剩余毫秒2:" + millSeconds2);
System.out.println("当天剩余秒2:" + count); //方法三:LocalDateTime和ChronoUnit为1.8新增
LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
long millSeconds = ChronoUnit.MILLIS.between(LocalDateTime.now(),midnight);
long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
System.out.println("当天剩余毫秒3:" + millSeconds);
System.out.println("当天剩余秒3:" + seconds); }
}
java时间操作:获取当天剩余时间的更多相关文章
- java时间操作
这篇讲的也很专业:http://soft.zdnet.com.cn/software_zone/2007/1129/660028.shtml java中的时间操作不外乎这四种情况: 1.获取当前时间 ...
- joda-time 2.5 包简化java时间操作
原文:https://www.ibm.com/developerworks/cn/java/j-jodatime.html Joda-Time 简介 既然无法摆脱时间,为何不设法简化时间处理? J P ...
- Java时间操作常用api
- 如何取得年月日.小时分钟秒?- 如何取得从1970年1月1日0时0分0秒到现在的毫秒数?- 如何取得某月的最后一天?- 如何格式化日期?答:问题1:创建java.util.Calendar 实例, ...
- java时间计算,获取某月第一天和最后一天
//获取前月的第一天 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); //获取当前月第一天: Calendar ...
- java 时间操作
设置获取时间日期格式 // 设置日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // 为 ...
- java字符操作获取汉字的拼音以及其它经常使用工具
公司需求年年有,今年有点小特殊,哈哈. 忽然加了个需求,说要实现汉字转拼音查询. 在努力下写出来了,如今分享一下吧!.! /** * 汉字转拼音缩写 * * @param str * 要转换的汉字字符 ...
- Java时间操作(一):关于UTC格式时间处理
Java中获取形如:20160811T122132+08 格式,可以通过如下方法 package com.mc.others; public class UTCTimeTest { @Test pub ...
- (转载) Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
1 . 查看当天日期 select current_date(); 2. 查看当天时间 select current_time(); 3.查看当天时间日期 select current_timesta ...
- Java时间串获取(格式:yyyyMMddHHmmss)
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");Calendar calendar = Calendar.getI ...
随机推荐
- python os.chdir() 用法
概述 os.chdir() 方法用于改变当前工作目录到指定的路径. 语法 chdir()方法语法格式如下: os.chdir(path) 参数 path -- 要切换到的新路径. 返回值 如果允许访问 ...
- java 8中列表对象多条件排序
java 8 新加了 lambda 表达式,当接口是一个 @FunctionalInterface 时可以使用 lambda 表达式代替 Function典型的应用场景为:A. 1个只有1个方法的接口 ...
- yarn 的安装
yarn的安装方法: https://yarn.bootcss.com/docs/install.html#linux-tab
- [svc]traceroute(udp+icmp)&tracert(icmp)原理
2018年4月11日 11:41:29更新 工具 发包 触发点 结局 traceroute 初始发udp包 ttl递增,icmp每一跳报ttl超时 udp端口不可达 tracert 初始发icmp r ...
- 【小白的CFD之旅】18 控制方程基础
忙碌了一个学期终于放暑假了,小白心情很愉快.然而想起CFD教材上的那些点缀着各种让人眼花缭乱符号的数学公式,整个人就不好了.不过这些事情小白也不好意思去麻烦师兄师姐们,还得靠自己去摸索.正好趁着暑假把 ...
- [Windows Azure] Building the web role for the Windows Azure Email Service application - 3 of 5
Building the web role for the Windows Azure Email Service application - 3 of 5. This is the third tu ...
- SolrCloud基本过程
转:http://www.data321.com/yunjisuan/20160514880/SolrZhiJieDuQuZKZhongDePeiZhiXin SolrCloud之分布式索引及与Zoo ...
- 网页安装ipa
在网页上直接下载并安装ipa,兼容所欲iso,包含没有越狱的 1.html代码 <a href="itms-services://?action=download-manifest&a ...
- Linux源码分析之:malloc、free
之前写代码的时候一直有个疑问,malloc申请内存的时候指定了内存大小,但是free的时候却只指定要释放的内存地址,那么free是如何知道它要释放的内存空间大小呢? 源码之前,了无秘密,下面就从源码来 ...
- Python(五)之迭代器和列表解析
Python迭代器和列表解析 迭代器 例如: In [1]: l1 = [1,2,3,4,5] dir(i1)可以看到内置方法'__iter__' 生成一个迭代器: l1.__iter__,或i2 = ...