jodatime

How to import FromString for joda-time?

£可爱£侵袭症+ 提交于 2019-12-05 02:09:49
I try to use joda-time library for easier measuring the execution time of my program (not for profiling, just for the user). But when I compile my project I get error about missing dependency -- the "FromString" class is missing. I tried to explicitly import it, but while typing intellisense (IntelliJ) does not even detect it, on the other hand there is only one jar for download from joda-time site. How do I resolve this dependency? I am aware of wrapper for JT but for now I would like to use it directly. Suminda Sirinath S. Dharmasena If the problem is with FromString , then the missing

Date and Time helper for PHP (like Joda-Time in Java) [closed]

不羁岁月 提交于 2019-12-05 01:54:19
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I am looking for a library (open source) like Joda-Time in the Java world. Is there any library like that? Joda-Time is very helpful to calculate date and time. I can add days, weeks, month, year and also can converting date and time easily. I wish there is library like Joda-Time for PHP. Edit: I need some functions that available in Joda-Time like daysBetween (to calculate number of days between 2 date),

Migrating from Java Calendar to Joda Date Time

為{幸葍}努か 提交于 2019-12-05 01:28:00
Previously, when I first design a stock application related software, I decide to use java.util.Date to represent date/time information of a stock. Later, I realize most of the methods in java.util.Date is deprecated. Hence, very soon, I refactor all my code to make use of java.util.Calendar However, there is 2 shortcomings I encounter. Construct java.util.Calendar is comparative slower than java.util.Date Within the accessors getCalendar method of Stock class, I need to clone a copy, as Calendar is a mutable class Here is the current source code for Stock.java Recently, I discover Joda-Time .

Count Down to Christmas with Joda-Time

岁酱吖の 提交于 2019-12-05 00:29:27
问题 I am trying to implement Joda-Time to count down to Christmas, but so far I'm struck. I tried java.util.Date and most StackOverflow questions and answers suggested to use Joda-Time. But I can't get it working. Some codes give different answers. Here are some codes I tried, DateTime now = new DateTime(); DateTime christmas = new DateTime(2012, 12, 25, 8, 0, 0, 0); Days daysToChristmas = Days.daysBetween(today, christmas); System.out.println(daysToChristmas.toString()); And this prints P187D as

Is it safe to use DateTimeUtils.setCurrentMillisFixed in tests?

无人久伴 提交于 2019-12-05 00:06:23
In order to test time-dependent code it's good to use Virtual Clock Pattern The idea is that we pull current time not using new Date , but from a clock which can be mocked with virtual clock returning predefined fixed time. Now in Java we have JodaTime with DateTime class and which allows to set sample time with DateTimeUtils.setCurrentMillisFixed(today.getMillis()); And reset the fixed time to a system time with: DateTimeUtils.setCurrentMillisSystem(); Here is a good article on how to use it with TestNG. Now the question! How safe it's to use this technique with setUp and tearDown methods if

Joda-Time, Time without date

浪尽此生 提交于 2019-12-04 22:56:50
I want a Class that only stores the time and not the date or day. Is there a class for this in Joda-Time ? or do I have to use a Date time and convert only the time part into a string and then use that part ? There's the LocalTime class for that purpose. Read more about partials here . E.g.: LocalTime time = new LocalTime(12, 20); String formatted = time.toString("HH:mm"); LocalTime - Immutable class representing a time without a date (no time zone) Check out this Since JodaTime 2.0, it's also possible to instanciate a time without date like this: LocalTime time = LocalTime.parse( // "12h20",

Equivalent to jodatime Interval in Java 8 Date and Time API [duplicate]

大憨熊 提交于 2019-12-04 22:12:49
This question already has an answer here: Is there a class in java.time comparable to the Joda-Time Interval? 4 answers The Java 8 way of dealing with time seems to have improved so much that I start to think about replacing jodatime in some cases. But what I am missing is an equivalent to the Interval class. I haven't dug too deep into Java 8 yet, so I might have missed something there. Does anyone have ideas on how intervals could be best dealt with? Meno Hochschild No way, the Joda class Interval does not exist in JSR-310. The concepts of Duration , Period etc. denotes temporal amounts

Joda-Time: Get max number of weeks for particular year

狂风中的少年 提交于 2019-12-04 19:56:20
问题 How do I get the maximum number of weeks for a particular year with Joda-Time? 回答1: new DateTime().withYear(PARTICULAR_YEAR).weekOfWeekyear().getMaximumValue(); @cody Comment Difference between the two methods .withWeekOfWeekyear() and .withWeekyear() Example new DateTime().withDate(2011, 1, 2); 2/1/2011 : Sunday, last day of last week of 2010 (27/12/2010 - 2/1/2011) dayOfWeek : 7 weekOfWeekyear : 52 weekyear : 2010 new DateTime().withDate(2011, 1, 3); 3/1/2011 : Monday, first day of first

How to convert Joda time LocalTime to java.util.Date?

£可爱£侵袭症+ 提交于 2019-12-04 19:36:28
I want to convert Joda LocalTime to java.util.Date and not LocalDate. If this helps, I already have a LocalTime object with me. Obviously, there is no "date" part in LocalTime. So I cannot convert LocalTime to Date directly. Is there a simple way to do this ? Steps - LocalTime loct LocalDate locd = Todays date + loct Date da = locd.toDate(); Date da = loct.toDateTimeToday().toDate(); Have you tried locd.withFields(loct).toDate(); You can also use this-- Date dtUtil = DateTime.now(DateTimeZone.getDefault()).toDate(); the generic way is - Date dtUtil = DateTime.now(DateTimeZone.forID(

Get the difference between two dates in hours

大城市里の小女人 提交于 2019-12-04 18:47:35
I'm trying to calculate the hour difference between two joda dates. val d1 = getDateTime1() val d2 = getDateTime2() Here is what I did: # attemp1 val hours = Hours.hoursBetween(d1, d2) // error - types mismatch # attempt2 val p = Period(d1, d2, PeriodType.hours()) // error - there is such a constructor p.getHours So how do I do this? The type of getDateTime1 should be org.joda.time.DateTime . This woks fine: val d1: org.joda.time.DateTime = DateTime.now val d2: org.joda.time.DateTime = DateTime.nextMonth val hours = Hours.hoursBetween(d1, d2) // org.joda.time.Hours = PT672H There is no factory