How to serialize Joda DateTime with Jackson JSON processor?

This has become very easy with Jackson 2.0 and the Joda module. ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); Maven dependency: <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-joda</artifactId> <version>2.1.1</version> </dependency> Code and documentation: https://github.com/FasterXML/jackson-datatype-joda Binaries: http://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-joda/

String to LocalDate

java.time Since Java 1.8, you can achieve this without an extra library by using the java.time classes. See Tutorial. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy-MMM-dd”); formatter = formatter.withLocale( putAppropriateLocaleHere ); // Locale specifies human language for translating, and cultural norms for lowercase/uppercase and abbreviations and such. Example: Locale.US or Locale.CANADA_FRENCH LocalDate date = LocalDate.parse(“2005-nov-12”, formatter); The syntax … Read more

How to find difference between two Joda-Time DateTimes in minutes

Something like… DateTime today = new DateTime(); DateTime yesterday = today.minusDays(1); Duration duration = new Duration(yesterday, today); System.out.println(duration.getStandardDays()); System.out.println(duration.getStandardHours()); System.out.println(duration.getStandardMinutes()); Which outputs 1 24 1440 or System.out.println(Minutes.minutesBetween(yesterday, today).getMinutes()); Which is probably more what you’re after

Convert LocalDate to LocalDateTime or java.sql.Timestamp

JodaTime To convert JodaTime’s org.joda.time.LocalDate to java.sql.Timestamp, just do Timestamp timestamp = new Timestamp(localDate.toDateTimeAtStartOfDay().getMillis()); To convert JodaTime’s org.joda.time.LocalDateTime to java.sql.Timestamp, just do Timestamp timestamp = new Timestamp(localDateTime.toDateTime().getMillis()); JavaTime To convert Java8’s java.time.LocalDate to java.sql.Timestamp, just do Timestamp timestamp = Timestamp.valueOf(localDate.atStartOfDay()); To convert Java8’s java.time.LocalDateTime to java.sql.Timestamp, just do Timestamp timestamp = Timestamp.valueOf(localDateTime);

What’s the standard way to work with dates and times in Scala? Should I use Java types or there are native Scala alternatives?

From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310). There are efforts on creating scala libraries wrapping java.time for scala such as scala-time. If targeting lower than SE 8 use one of the below. Also see Why JSR-310 isn’t Joda-Time Awesome scala lists many of the popular Scala DateTime apis A … Read more

Joda-Time: what’s the difference between Period, Interval and Duration?

3 classes are needed because they represent different concepts so it is a matter of picking the appropriate one for the job rather than of relative performance. From the documentation with comments added by me in italics: An interval in Joda-Time represents an interval of time from one millisecond instant to another instant. Both instants … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)