sqldatetime

Converting java date to Sql timestamp

大城市里の小女人 提交于 2019-11-28 07:08:41
I am trying to insert java.util.Date after converting it to java.sql.Timestamp and I am using the following snippet: java.util.Date utilDate = new java.util.Date(); java.sql.Timestamp sq = new java.sql.Timestamp(utilDate.getTime()); But this is giving me sq as 2014-04-04 13:30:17.533 Is there any way to get the output without milliseconds? You can cut off the milliseconds using a Calendar : java.util.Date utilDate = new java.util.Date(); Calendar cal = Calendar.getInstance(); cal.setTime(utilDate); cal.set(Calendar.MILLISECOND, 0); System.out.println(new java.sql.Timestamp(utilDate.getTime()))

How to convert LocalDate to SQL Date Java?

﹥>﹥吖頭↗ 提交于 2019-11-27 11:52:06
How do I convert a LocalDate to a java.sql.Date ? Attempt: Record r = new Record(); LocalDate date = new Date(1967, 06, 22); r.setDateOfBirth(new Date(date)); This fails (won't compile) and all I can find is Joda time stuff. I'm using Java 8 The answer is really simple; import java.sql.Date; ... LocalDate locald = LocalDate.of(1967, 06, 22); Date date = Date.valueOf(locald); // Magic happens here! r.setDateOfBirth(date); If you would want to convert it the other way around, you do it like this: Date date = r.getDate(); LocalDate localD = date.toLocalDate(); r is the record you're using in JOOQ

.NET DateTime to SqlDateTime Conversion

穿精又带淫゛_ 提交于 2019-11-27 08:32:58
While converting .NET DateTime (when is default(DateTime)) to SqlDateTime should I always check if the .NET date is between SqlDateTime.MinValue and SqlDateTime.MaxValue [or] Is there a good way to do this. Is it possible that the date could actually be outside that range? Does it come from user input? If the answer to either of these questions is yes, then you should always check - otherwise you're leaving your application prone to error. You can format your date for inclusion in an SQL statement rather easily: var sqlFormattedDate = myDateTime.Date.ToString("yyyy-MM-dd HH:mm:ss"); If you are

Converting java date to Sql timestamp

廉价感情. 提交于 2019-11-27 05:41:27
问题 I am trying to insert java.util.Date after converting it to java.sql.Timestamp and I am using the following snippet: java.util.Date utilDate = new java.util.Date(); java.sql.Timestamp sq = new java.sql.Timestamp(utilDate.getTime()); But this is giving me sq as 2014-04-04 13:30:17.533 Is there any way to get the output without milliseconds? 回答1: You can cut off the milliseconds using a Calendar : java.util.Date utilDate = new java.util.Date(); Calendar cal = Calendar.getInstance(); cal.setTime

.NET DateTime to SqlDateTime Conversion

做~自己de王妃 提交于 2019-11-26 14:10:58
问题 While converting .NET DateTime (when is default(DateTime)) to SqlDateTime should I always check if the .NET date is between SqlDateTime.MinValue and SqlDateTime.MaxValue [or] Is there a good way to do this. 回答1: Is it possible that the date could actually be outside that range? Does it come from user input? If the answer to either of these questions is yes, then you should always check - otherwise you're leaving your application prone to error. You can format your date for inclusion in an SQL