简体   繁体   English

如何将sql date转换为Joda Datetime?

[英]How to convert sql date to Joda Datetime?

I'm working with date sql and getDay() returns the day of the week represented by this date. 我正在使用日期sql和getDay()返回此日期表示的星期几。 The returned value ( 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday ) 返回值( 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);

Example : value of the dateStart : 2015-07-01 and dateStart.getDay() return 2015-07-03 (3 = Wednesday) 示例:dateStart的值:2015-07-01和dateStart.getDay()返回2015-07-03(3 =星期三)

I want dateStart.getDay() get this value 1 我希望dateStart.getDay()获得此值1

How about using new DateTime(dateStart.getTime()) ? 如何使用new DateTime(dateStart.getTime())

To get the day (of the month) from a java.sql.Date , you have to use getDate . 要从java.sql.Date (每月的)日期,必须使用getDate This method is inherited from java.util.Date and deprecated. 此方法继承自java.util.Date并已弃用。 The correct way to get parts from a date is to use a Calendar . 从日期获取零件的正确方法是使用Calendar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM