https://blog.csdn.net/dongfangbaiyun/article/details/51225469

java之比较两个日期大小

最近又用到两个日期大小的比较,因此记录在此,方便以后查阅。

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; /**
* 比较日期大小
*/
public class TestDateCompare { static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式 public static void main(String[] args) throws ParseException {
Date startDate = sdf.parse("2016-04-15 11:11:11");
Date endDate = sdf.parse("2016-04-16 11:11:11"); if(startDate.before(endDate)){
System.out.println("startDate小于endDate");
}else if(startDate.after(endDate)){
System.out.println("startDate大于endDate");
}else{
System.out.println("startDate等于endDate");
} if(endDate.after(startDate)){
System.out.println("endDate大于startDate");
} System.out.println(startDate.compareTo(endDate));
System.out.println(endDate.compareTo(startDate));
System.out.println(endDate.compareTo(endDate));
}
}

运行结果: 
startDate小于endDate 
endDate大于startDate 
-1 

0

java之比较两个日期大小----https://blog.csdn.net/dongfangbaiyun/article/details/51225469的更多相关文章

  1. 转-java编译时error: illegal character '\ufeff' 的解决办法-https://blog.csdn.net/t518vs20s/article/details/80833061

    原文链接:https://blog.csdn.net/shixing_11/article/details/6976900 最近开发人员通过SVN提交了xxx.java文件,因发布时该包有问题需要回退 ...

  2. java 生成20位唯一ID,生成不会重复的20位数字----https://blog.csdn.net/weixin_36751895/article/details/70331781

    java 生成20位唯一ID,生成不会重复的20位数字----https://blog.csdn.net/weixin_36751895/article/details/70331781

  3. Java类和对象 详解(一)---写的很好通俗易懂---https://blog.csdn.net/wei_zhi/article/details/52745268

    https://blog.csdn.net/wei_zhi/article/details/52745268

  4. 程序员的沟通之痛https://blog.csdn.net/qq_35230695/article/details/80283720

    个人理解: 一般刚工作的程序员总觉得技术最重要.但是当工作年限超过3年.或者岗位需要涉及汇报.需求对接等就会发现沟通非常重要.也许在大公司还不那么明显,但是在小公司.小团队或者创业,沟通甚至可以说是第 ...

  5. [Android Pro] https://blog.csdn.net/gaugamela/article/details/79143309

    原文地址:https://blog.csdn.net/gaugamela/article/details/79143309 最近遇到这样一个问题: 第三方的SDK除了Jar包外,还提供了对应的so文件 ...

  6. 手把手教你如何玩转消息中间件(ActiveMQ) https://blog.csdn.net/cs_hnu_scw/article/details/81040834

    #情景引入小白:起床起床起床起床....快起床~我:怎么了又,大惊小怪,吓到我了.小白:我有事有事想找你,十万火急呢~~我:你能有什么事?反正我不信..那你说说看~~小白:就是我有两个小表弟,叫大白和 ...

  7. https://blog.csdn.net/u011489043/article/details/68488459

    转自https://blog.csdn.net/u011489043/article/details/68488459 String 字符串常量   StringBuffer 字符串变量(线程安全) ...

  8. 自动车牌识别(ALPR)---https://blog.csdn.net/ELEVEN_ZOU/article/details/80893579

    1.基本功能:从一张或者一系列的图片中提取车牌信息,比如车牌号码.车牌颜色等信息. 2.功能扩展:车型.车品牌.车牌类型等. 3.应用方向:电子交易系统(停车自动收费.收费站自动支付等).交通执法.交 ...

  9. Nginx 配置location root 转自https://blog.csdn.net/rofth/article/details/78581617

    nginx指定文件路径有两种方式root和alias,root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上. 最基本的区别 ...

随机推荐

  1. KeepAlived的配置

    KeepAlived的相关配置 KeepAlived 配置 参考帮助 man keepalived.conf 配置文件组件部分: top hierachy(层次) global configurati ...

  2. CodeForces 731C Socks (DFS或并查集)

    题意:有n只袜子,k种颜色,在m天中,问最少修改几只袜子的颜色,可以使每天穿的袜子左右两只都同颜色. 析:很明显,每个连通块都必须是同一种颜色,然后再统计最多颜色的就好了,即可以用并查集也可以用DFS ...

  3. 【weiphp】安装中报错

    问题描述:安装的第三部报错“SQLSTATE[HY000]: General error: 2030 This command is not supported in the prepared sta ...

  4. Hexo 添加Live2D看板娘

    title: Hexo 添加 Live2D看板娘 二次元什么的最喜欢了[大好きです] 准备 项目地址 live2d模型 部分模型预览 开始 首先进入Hexo博客根目录安装live2d插件 $ npm ...

  5. 【转】mysql中select用法

    转自:http://blog.sina.com.cn/s/blog_a74f39a201013c3b.html 1.选择所有的记录 select * from table_name; 其中*表示表中的 ...

  6. JavaScript相关技术学习

    百度前端技术学院 http://ife.baidu.com/task/all 框架 JQuery 简单Web论坛  https://github.com/huanshen/web-bbs http:/ ...

  7. Git学习笔记(0)-错误汇总

    一.LF will be replaced by CRLF 1.发现问题 $ git add welcome.txt warning: LF will be replaced by CRLF in w ...

  8. [ Luogu 3927 ] Factorial

    \(\\\) \(Description\) 求 \(N!\) 在 \(K\) 进制表示下末尾 \(0\) 的个数. \(N,K\in [1,10^{12}]\) \(\\\) \(Solution\ ...

  9. TensorFlow OOM when allocating tensor with shape[5000,384707]

    在session范围内不要进行eval()或者convert_to_tensor()操作, 否则会造成OOM,或者报出错误:GraphDef cannot be larger than 2GB usi ...

  10. Android基础TOP6_1:FrameLyayout和ImageView制作层叠图片

    Activity: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...