判断是否为同一天

private static boolean isSameDate(Date date1, Date date2) {
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
boolean isSameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR);
boolean isSameMonth = isSameYear && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
boolean isSameDate = isSameMonth && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
return isSameDate;
}

时间: 2024-08-09 04:57:43

判断是否为同一天的相关文章

StringUtils 时间显示,判断手机号,电子邮件,是否为今日,是否空白串,字符串转整数,对象转整数 等

1 package com.xiaoyun.org.util; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 7 import java.text.ParseException; 8 import java.text.SimpleDateFormat; 9 import java.u

java采用DateFormat日期格式化方法判断用户今天是否第一次登录(比较简单)

一.描述 1.数据库中有一个date类型的last_login_time字段,即用户每次登录都会更新该字段: 2.在登录时使用jdbcTemplate的queryForObject方法,取出last_login_time字段的值以Date类型返回,并用DateFormat格式化该时间 3.获取系统当前时间,并用DateFormat格式化,比较两个时间是否相等就可以判断该用户今天是否第一次登录. 上次我写的判断用户当天是否第一次登录的方法采用字符串的比较方式,使用起来很繁琐,效率也不高,因此今天进

使用DateUtils和DateFormatUtils处理时间日期转换与SimpleDateFormat的区别

在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.time包下. 1. 与SUN的SimpleDateFormat相比,其主要优点是:线程安全. 2. 对应于SimpleDateFormat的format()的方法,是DateFormatUtils 的format系列方法,常用的就是: public static java.lang.String for

时间格式转换 - 时间戳 、、、、

js中的日期格式化 function timeStamp2String(time) { var datetime = new Date(); datetime.setTime(time); var year = datetime.getFullYear(); var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1; var date =

【转】apache DateFormatUtils 与 DateUtils 的使用

在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.time包下. 1. 与SUN的SimpleDateFormat相比,其主要优点是:线程安全. 2. 对应于SimpleDateFormat的format()的方法,是DateFormatUtils 的format系列方法,常用的就是: public static Java.lang.String for

如何将时间改为显示:几天前,几小时前,或者几分钟前

http://www.oschina.net/question/657074_89320#tags_nav 如这样的  最后发帖:2011-01-05 12:33 要改成这样怎么实现: 最后发表:  2分钟前 最后发表:  28秒前 最后发表:  2025-04-18   最后发表:  2小时前 最后发表: 2天前 解答: 创建时间-当前时间 如果在60秒之内显示多少秒之前, 如果大于60秒在60分之内,显示多少分 ……以此类推 timemap加减 个人做法是保存时间戳,然后在前端用jq插件做转

【ListViewJSON】【com.demo.app.common】【StringUtils】源码分析及其在工程中作用

源码如下: package com.demo.app.common; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONException; import

js时间的一些处理

判断是否为同一天 function isSameFay(t) { return new Date(t).toDateString() === new Date().toDateString(); }   原文地址:https://www.cnblogs.com/justsilky/p/11555782.html

如何判断两个时间是否是同一天

- (void)viewDidLoad { [super viewDidLoad]; NSString *d = @"2015-03-05 23:59:59"; NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"yyyy:MM:dd HH:mm:ss"]; NSDate *date = [format dateFromString:d]; NSLog(@