I have to insert data(which is also containing the timezone, i.e. 2013-01-19 00:00:00 +0530) which is in String form and the datatype of the column is DATETIMEOFFSET. I have tried both java.util.date and sql.date but could not find any solution.
I have to insert data(which is also containing the timezone, i.e. 2013-01-19 00:00:00 +0530)
Share
If you’re using the Microsoft JDBC driver, you can use the
DateTimeOffsetclass, constructing instances with thevalueOfmethod.You’ll need to parse the value out into local time and offset (in order to pass the two parts separately) but that shouldn’t be too bad using
SimpleDateFormat. (TheZformat specifier inSimpleDateTimeFormatwill handle offsets like +0530.) Alternatively, use Joda Time which will make life easier still, as it will allow you to parse to aDateTimewhich lets you get the offset as well as the local time in one go. I would personally use Joda Time and create a method to convert from aDateTimeto aDateTimeOffset.