How to serialize and deserialize Java 8’s java.time types with Gson? [closed]

There’s a Java 8 library here: https://github.com/gkopff/gson-javatime-serialisers Here’s the Maven details (check central for the latest version): <dependency> <groupId>com.fatboyindustrial.gson-javatime-serialisers</groupId> <artifactId>gson-javatime-serialisers</artifactId> <version>1.1.1</version> </dependency> And here’s a quick example of how you drive it: Gson gson = Converters.registerOffsetDateTime(new GsonBuilder()).create(); SomeContainerObject original = new SomeContainerObject(OffsetDateTime.now()); String json = gson.toJson(original); SomeContainerObject reconstituted = gson.fromJson(json, SomeContainerObject.class);

Convert a string with ‘YYYYMMDDHHMMSS’ format to datetime

You can use the STUFF() method to insert characters into your string to format it in to a value SQL Server will be able to understand: DECLARE @datestring NVARCHAR(20) = ‘20120225143620’ — desired format: ‘20120225 14:36:20′ SET @datestring = STUFF(STUFF(STUFF(@datestring,13,0,’:’),11,0,’:’),9,0,’ ‘) SELECT CONVERT(DATETIME, @datestring) AS FormattedDate Output: FormattedDate ======================= 2012-02-25 14:36:20.000 This approach will work … Read more