概述
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Main {
/**
* Method to convert a calendar object to java's epoch date keeping only the
* time information
*/
public static Date toEpochDate(Calendar calendar) {
return new Date(Time.valueOf(
new SimpleDateFormat("HH:mm:ss").format(calendar.getTime())).getTime());
}
public static void main(String[] args) {
Calendar someTime = Calendar.getInstance();
someTime.set(Calendar.HOUR_OF_DAY, 17);
someTime.set(Calendar.MINUTE, 0);
someTime.set(Calendar.SECOND, 0);
// convert it to java epoch date
Date someDate = toEpochDate(someTime);
// create a date object from java.sql.Time
Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime());
// now do the comparison
System.out.println("Some Date: " + someDate.toString());
System.out.println("Sql Time: " + fromSqlTime.toString());
System.out.println("Are they equal? " + someDate.equals(fromSqlTime));
}
}
最后
以上就是激情外套为你收集整理的java比较时间sql_Java Data Type - 如何将日历的时间与java.sql.Time对象进行比较的全部内容,希望文章能够帮你解决java比较时间sql_Java Data Type - 如何将日历的时间与java.sql.Time对象进行比较所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复