jodatime

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

家住魔仙堡 提交于 2019-12-06 19:10:41
问题 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

Why are Joda objects immutable?

好久不见. 提交于 2019-12-06 17:30:33
问题 I have read that with a Java version less than 7, Joda Time objects are more reliable than Java's built-ins. One cited reason is that Joda objects are immutable. Why is this beneficial? If I want to change the year, hour, and timezone of a Joda DateTime object, I need to make three copies! 回答1: If I want to change the year, hour, and timezone of a Joda DateTime object, I need to make three copies! Yes, indeed. Or you could create one new object, using all the fields you like from the old

Is it safe to use DateTimeUtils.setCurrentMillisFixed in tests?

筅森魡賤 提交于 2019-12-06 17:00:38
问题 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

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

亡梦爱人 提交于 2019-12-06 16:29:55
问题 This question already has answers here : Is there a class in java.time comparable to the Joda-Time Interval? (4 answers) Closed 3 years ago . 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? 回答1: No way, the

Joda LocalTime Meridiem parse

只愿长相守 提交于 2019-12-06 14:33:59
问题 When I use 08:00 AM as startTime and 09:00 AM as endTime then my if statement works perfect LocalTime selected = new LocalTime(hourOfDay, minute); if (selected.isAfter(startTime) && selected.isBefore(endTime)) { // doing some work } But whenever i use 11:00 PM as startTime and 02:00 AM as endTime then my if statement not working. LocalTime startTime = LocalTime.parse("11:00 PM", DateTimeFormat.forPattern("KK:mm a")); LocalTime endTime = LocalTime.parse("02:00 AM", DateTimeFormat.forPattern(

Play Framework 2.1 Remove a core dependency

妖精的绣舞 提交于 2019-12-06 14:21:49
since a few day now i'm trying to use Joda-time 1.6.2 on a play project. I know the play framework already come with the Joda-time 2.1 and it should be compatible with 1.6.2 according to joda-time site. I'm trying to write an application that ask the user for a LocalDateTime and save the class with the attributes on a MongoDB using morphia. I'm facing a problem, i have to use a class that are currently using joda-time 1.6.2 and i cannot change it dependency neither update it to 2.1. Since i have no use for the joda-Time 2.1, is it possible some how remove this dependency from Play Framework 2

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

蓝咒 提交于 2019-12-06 13:44:05
问题 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(); 回答1: Date da = loct.toDateTimeToday().toDate(); 回答2: Have you tried locd.withFields(loct).toDate(); 回答3: You can also use this-- Date dtUtil = DateTime

Using Groovy(or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.date?

感情迁移 提交于 2019-12-06 11:45:24
Using Groovy (or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.Date ? import org.joda.time.* Calendar cal = Calendar.instance cal.set(Calendar.DATE, 1) cal.set(Calendar.HOUR, 0) cal.set(Calendar.MINUTE, 0) cal.set(Calendar.SECOND, 0) cal.set(Calendar.MILLISECOND, 0) Date startOfTheMonth = cal.time LocalDateTime localDateTime = new LocalDateTime() localDateTime = localDateTime.withDayOfMonth(1) localDateTime = localDateTime.withTime(0,0,0,0) localDateTime.minusMonths(6) Date dateFromLocalDate = localDateTime.toDateTime().toDate() println startOfTheMonth println

Duration with daylight saving

不羁的心 提交于 2019-12-06 11:33:54
I have an object Shift , with two fields: startDateTime and endDateTime as DateTime from Joda-Time. And my shift includes Daylight Saving UK change. It starts on 25/03/2017 13:00 and ends on 26/03/2017 02:00 (basically should end on 26/03/2017 01:00 , but this date does not exists, and endDate is shifted +1 hour). According to this site : When local standard time was about to reach Sunday, 26 March 2017, 01:00:00 clocks were turned forward 1 hour to Sunday, 26 March 2017, 02:00:00 local daylight time instead. Now if I want to track the number of hours worked by a employee new Duration

Change timezone of Date object without changing date

拜拜、爱过 提交于 2019-12-06 11:18:45
问题 Can I change the timezone of Date object in my java code without changing the date? When I write Date date = new Date(longValue); I get this date in my local timezone. I want to get this date but my timezone should be one present in DB (not local) for my userID (for eg "America/Chicago"). Thanks in advance for your help. 回答1: tl;dr ZonedDateTime zdtMontreal = ZonedDateTime.now( ZoneId.of( "America/Montreal" ) ); ZonedDateTime zdtAuckland = zdtMontreal.withZoneSameLocal( ZoneId.of( "Pacific