jodatime

What are the differences between Joda LocalDate and java.util's Date?

别等时光非礼了梦想. 提交于 2019-12-08 00:51:16
问题 I was just wondering what the differences between Joda's LocalDate class and java.util's Date class were. Also, are there any advantages in using one over the other? 回答1: I think the Joda Time Website explains it all very well. Joda-Time has been created to radically change date and time handling in Java. The JDK classes Date and Calendar are very badly designed, have had numerous bugs and have odd performance effects. Here are some of our reasons for developing and using Joda-Time: Easy to

Convert seconds to years/days/hours/minutes automatically, using JodaTime?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 00:46:30
问题 Is there way to convert 'x' seconds to y hours and z seconds when say x exceeds 3600 seconds? Similarly, convert it to 'a minutes and b seconds' when x exceeds 60 but is less than 3600 seconds, using JodaTime? I understand that I would have to specify what I need in the PeriodFormatter, but I don't want to specify it - I want a formatted text based on value of seconds. This is similar to how you would post on a forum and then your post will initially be shown as 'posted 10 seconds ago'..

Joda-Time all in minutes

你。 提交于 2019-12-07 22:46:39
问题 Is there a hidden way to get a Joda-Time period in minutes (or any other) Right now I do: (period.getHours()*60 + period.getMinutes() + roundTwoDecimals((double)(period.getSeconds()/60))) double roundTwoDecimals(double d) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } But for some reason I think there could be an easier way. EDIT: My times will be max hours, and will never be days. This is my first time with Joda-Time. 回答1: Since Period s

Joda-Time, daylight savings calculation, timezone independent tests

蓝咒 提交于 2019-12-07 21:59:11
问题 We use fixed time periods in the application. When the user adds a new period, it should be by default from 6:00 AM to 6:00 AM the next day. Normally, it's 24 hours, but there is one issue : when the daylight saving change is performed, the length of that period changes. For example : 27 October 6:00 AM to 28 October 6:00 AM. In this period is performed change shift from CEST to CET time zone. Thus, this period contains 25 hours : From 27 October 6:00 AM to 28 October 3:00 AM - there are 21

Android force close with JodaTime

余生颓废 提交于 2019-12-07 19:36:20
问题 Has anybody used jodatime with android? I'm getting a force close with no trace. package test.journal.help; import java.util.Date; import org.joda.time.DateTime; import org.joda.time.Days; import android.app.Activity; import android.os.Bundle; public class journaltester extends Activity { /** Called when the activity is first created. */ private Date today = new Date(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Days days = Days.daysBetween(new

JodaTime LocalDate/LocalTime not Parsing with custom JSON Serializer classes

元气小坏坏 提交于 2019-12-07 18:32:48
问题 I have an object called ReportEvent which takes in a LocalTime as well as a LocalDate from the JodaTime API/framework. This ReportEvent is able to be written to JSON via google's GSON conversion API. However when deserializing the JodaTime partial causes problems. Logcat Error Report: 10-16 13:23:01.812: E/AndroidRuntime(8884): FATAL EXCEPTION: main 10-16 13:23:01.812: E/AndroidRuntime(8884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nanospark.cnc/com.nanospark

Compare Intervals (JodaTime) in a list for overlap

荒凉一梦 提交于 2019-12-07 13:23:17
问题 I have a list of intervals, and I need to compare them for overlaps. List<Interval> intervals = new ArrayList<>(); intervals.add(new Interval(dateTime1, dateTime2)); intervals.add(new Interval(dateTime3, dateTime4)); intervals.add(new Interval(dateTime5, dateTime6)); eg. dateTime1 = 2014-06-01 dateTime2 = 2014-07-01 dateTime3 = 2014-08-01 dateTime4 = 2014-09-01 dateTime5 = 2014-08-15 dateTime6 = 2014-09-15 In this case, there is an overlap between the 2nd and the 3rd interval. I can use the

Eliminating the subtle whitespace handling difference between DateTimeFormat and Joda's DateTimeFormatter

强颜欢笑 提交于 2019-12-07 08:30:55
问题 We have some existing code like this: DateFormat[] dateFormats = { new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH), new SimpleDateFormat("d MMM yyyy HH:mm:ss Z", Locale.ENGLISH) }; For thread safety reasons, I tried to convert it to use Joda Time's formatters, so: DateTimeFormatter[] dateFormats = { DateTimeFormat.forPattern("EEE, d MMM yyyy HH:mm:ss Z") .withLocale(Locale.ENGLISH) .withOffsetParsed(), DateTimeFormat.forPattern("d MMM yyyy HH:mm:ss Z") .withLocale(Locale

Localised Date format without year with Joda Time

谁说胖子不能爱 提交于 2019-12-07 07:56:36
问题 I'm trying to achieve showing date in local format but without year. So should be: 12 June for UK June 12 for US Is it possible to achieve with Joda time? We've tried "dd MMMM" pattern but it doesn't work. We've tried StringFormat.longDate() and strip year info but are there more elegant solution? 回答1: Underneath the covers, JodaTime uses the JDK's java.text.DateFormat.getDateInstance(int style, Locale aLocale) - see the sources of org.joda.time.format.DateTimeFormat.StyleFormatter#getPattern

Leap second handling in database

半城伤御伤魂 提交于 2019-12-07 07:01:03
问题 As: The Unix time number is zero at the Unix epoch, and increases by exactly 86400 per day since the epoch. So it cannot represent leap seconds. The OS will slow down the clock to accomodate for this. So, if I am storing Unix epoch (e.g. ts) in DB (milli-second accuracy), how to handle the following case? How to make sure the the ts is always increasing and no backward? How to select exactly the 100s interval from db which take account into the leap second? e.g. SELECT * FROM events WHERE ts