如何将sql date转换为Joda Datetime?

时间:2015-08-10 16:04:47

标签: java date datetime jodatime

我正在使用date sql而getDay()返回此日期所代表的星期几。返回值(0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday

//type of dateStart and dateEnd is  java.sql.Date
//type of DateTime is joda.time.DateTime
public static Date[][] getListPeriod(Date dateStart , Date dateEnd){
DateTime start = new DateTime(dateStart.getYear()+1900,dateStart.getMonth()+1,dateStart.getDay(), 0, 0, 0, 0);

示例:dateStart的值:2015-07-01 并dateStart.getDay()返回2015-07-03(3 =星期三)

我希望dateStart.getDay()获得此值1

1 个答案:

答案 0 :(得分:2)

如何使用new DateTime(dateStart.getTime())

要从java.sql.Date获取当天(当月),您必须使用getDate。此方法继承自java.util.Date并已弃用。从日期获取零件的正确方法是使用Calendar