Skip to content

Tag: date

transform java.sql.Date to LocalDateTime

I have a java.sql.Date object and want to transform it to a java.time.LocalDateTime object. For comparison, I am able to do a similar transformation using java.util.Date: This answer doesn’t work for me, as my java.sql.Date does not have a getTimestamp method. For reference, this question addresses the …

Parse datetime with offset string to LocalDateTime

I am trying to parse following datetime String to LocalDateTimeObject, however I am not able to identify the format of the datetime string. Sat, 09 Oct 2021 02:10:23 -0400 How should I determine the pattern of the above string? Answer You should first check if the date string matches any of the Predefined For…

Java Object Mapper date conversion to Json

I am using ObjectMapper to convert a list of objects to JSON, however the date field converts into key-value see below current output current output: Output expected is My code: User Class Answer by registering the JavaTimeModule the issue is resolved

Get Timestamp in specific format

I have a timestamp saved in Azure SQL Database in the format of 2004-09-23 10:52:00. When I fetch the value, I am using sqlrowset where I am using getString(“last_updated_user”) and getting output like this “2004-09-23 10:52:00.0”. When I tried using getTimeStamp(“last_updated_us…

datetime conversion to Java in SQLServer 2016

I have a scenario where I have a table that has a date field with the datetime property. In the documentation (https://learn.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver15) : Note that java.sql.Timestamp values can no longer be used to compare values from a datetime column s…

Unable to find Dateformat

I know this is a very silly question but I’m unable to find a suitable dateformatter for the given Date: 2020/04/01T20:00-05:00 or 2020/03/05T21:45-07:00. Any sort of help would be highly appreciated. Answer You can’t find one because that is a non-standard format. – is industry standard, us…