jodatime

Differences between java.util.Date and Joda Time APIs [duplicate]

安稳与你 提交于 2019-12-17 19:13:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Should I use Java date and time classes or go with a 3rd party library like Joda Time? I could use some guidance about when it's worth using Joda Time rather than the basic java.util.Date class. What are the benefits? Does Joda Time let you do anything you can't do with the Date class, or is it just easier to work with or what? Also, I've seen conflicting info about whether Joda Time is part of the standard API.

How to handle jodatime Illegal instant due to time zone offset transition

亡梦爱人 提交于 2019-12-17 18:01:13
问题 I want to set up joda DateTime to today at 2 AM (see sample code below). But I'm getting this exception: Exception in thread "main" org.joda.time.IllegalFieldValueException: Value 2 for hourOfDay is not supported: Illegal instant due to time zone offset transition: 2011-03-27T02:52:05.239 (Europe/Prague) at org.joda.time.chrono.ZonedChronology$ZonedDateTimeField.set(ZonedChronology.java:469) at org.joda.time.MutableDateTime.setHourOfDay(MutableDateTime.java:702) What is the correct way to the

Why do I get a NoSuchMethodError on JodaTime.withYear()?

Deadly 提交于 2019-12-17 16:39:35
问题 I have a maven web app project, where I use JodaTime. JodaTime is not directly referenced in my maven project, but is a part of a transitive dependency. In other words, my web app war, has another project of mine as a direct dependency, and that jar contains JodaTime. I am getting an error after executing these two lines. It compiles fine though. DateTime firstDate = new DateTime(); firstDate = firstDate.withYear(2016); And here is my error: java.lang.NoSuchMethodError: org.joda.time.DateTime

Java Joda Time - Implement a Date range iterator

折月煮酒 提交于 2019-12-17 16:07:28
问题 I'm trying to implement without success a Date iterator with Joda time. I need something that allows me to iterate all the days form startDate to endDate Do you have any idea on how to do that? 回答1: Here's something to get you started. You may want to think about whether you want it to be inclusive or exclusive at the end, etc. import org.joda.time.*; import java.util.*; class LocalDateRange implements Iterable<LocalDate> { private final LocalDate start; private final LocalDate end; public

Spring @ResponseBody Jackson JsonSerializer with JodaTime

时光毁灭记忆、已成空白 提交于 2019-12-17 11:43:26
问题 I have below Serializer for JodaTime handling: public class JodaDateTimeJsonSerializer extends JsonSerializer<DateTime> { private static final String dateFormat = ("MM/dd/yyyy"); @Override public void serialize(DateTime date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException { String formattedDate = DateTimeFormat.forPattern(dateFormat).print(date); gen.writeString(formattedDate); } } Then, on each model objects, I do this: @JsonSerialize(using

First day of next month with java Joda-Time

泄露秘密 提交于 2019-12-17 11:31:31
问题 How would you rewrite the method below, which returns the first day of next month, with the org.joda.time package in Joda-Time? public static Date firstDayOfNextMonth() { Calendar nowCal = Calendar.getInstance(); int month = nowCal.get(Calendar.MONTH) + 1; int year = nowCal.get(Calendar.YEAR); Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, 1); Date dueDate = new Date(cal.getTimeInMillis());

First day of next month with java Joda-Time

吃可爱长大的小学妹 提交于 2019-12-17 11:31:00
问题 How would you rewrite the method below, which returns the first day of next month, with the org.joda.time package in Joda-Time? public static Date firstDayOfNextMonth() { Calendar nowCal = Calendar.getInstance(); int month = nowCal.get(Calendar.MONTH) + 1; int year = nowCal.get(Calendar.YEAR); Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, 1); Date dueDate = new Date(cal.getTimeInMillis());

Are there any cons to using Joda-Time?

一笑奈何 提交于 2019-12-17 10:24:16
问题 I want to convince the architecture manager to include the Joda-Time jar in our product. Do you know any disadvantages in using it? I think Joda-Time needs to be constantly updated because of the files that it includes. And that is a disadvantage. Maybe I am wrong. Could you provide some clarity on the subject? 回答1: I've had almost entirely positive experiences with Joda Time. My one problem was when trying to construct my own time zone (for legitimate reasons, I assure you :) I got some very

Is there a way to add maven dependencies while using the maven-jlink-plugin?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 06:51:42
问题 I'm using this Github project to get exposed to the new modular features in Java 9. I would like to add dependencies to the project and be able to build a native image. However, when I try to add a new dependency to the pom.xml, and add the requires statement to the module-info.java, I get a the following error from the maven-jlink-plugin: Error: module-info.class not found for joda.time module I'm trying to use this as a proof of concept that I can deploy images using the new linking phase,

Convert from java.util.date to JodaTime

不羁的心 提交于 2019-12-17 06:31:15
问题 I want to convert a java.util.Date to JodaTime so as to carry out subtractions between dates. Is there a good concise way to convert from Date to JodaTime ? 回答1: java.util.Date date = ... DateTime dateTime = new DateTime(date); Make sure date isn't null , though, otherwise it acts like new DateTime() - I really don't like that. 回答2: http://joda-time.sourceforge.net/quickstart.html Each datetime class provides a variety of constructors. These include the Object constructor. This allows you to