jodatime

Comparing two Joda-Time DateTime objects

青春壹個敷衍的年華 提交于 2019-12-03 09:25:08
I am dealing with something very similar to what has been asked here - compare Joda-Time time zones but it does not seem to work for me. Here's a piece of code which I am testing Joda-Time DateTime with - DateTime estDT = new DateTime(DateTimeZone.forID("America/Puerto_Rico")).withMillisOfSecond(0); DateTime londonDT = new DateTime(DateTimeZone.forID("Europe/London")).withMillisOfSecond(0); System.out.println("Comparison " + londonDT.isBefore(estDT)); System.out.println("Comparison " + londonDT.isAfter(estDT)); Interestingly enough, I get 'false' from both the sysout statements above. Can

Inclusive Date Range check in Joda Time

て烟熏妆下的殇ゞ 提交于 2019-12-03 09:19:18
问题 I am using Joda Time 2.1 library. I have written a method to compare if a given date is between a date range of not. I want it to be inclusive to the start date and end date.I have used LocalDate as I don't want to consider the time part only date part. Below is the code for it. isDateBetweenRange(LocalDate start,LocalDate end,LocalDate target){ System.out.println("Start Date : " +start.toDateTimeAtStartOfDay(DateTimeZone.forID("EST")); System.out.println("Target Date : "

In Joda-Time, set DateTime to start of month

无人久伴 提交于 2019-12-03 08:14:45
问题 My API allows library client to pass Date: method(java.util.Date date) Working with Joda-Time, from this date I would like to extract the month and iterate over all days this month contains. Now, the passed date is usually new Date() - meaning current instant. My problem actually is setting the new DateMidnight(jdkDate) instance to be at the start of the month. Could someone please demonstrates this use case with Joda-Time? 回答1: Midnight at the start of the first day of the current month is

Joda Time: Convert UTC to local

﹥>﹥吖頭↗ 提交于 2019-12-03 07:37:09
I want to convert a Joda Time UTC DateTime object to local time. Here's a laborious way to do it which seems to work. But there must be a better way. Here's the code (in Scala) without surrounding declarations: val dtUTC = new DateTime("2010-10-28T04:00") println("dtUTC = " + dtUTC) val dtLocal = timestampLocal(dtUTC) println("local = " + dtLocal) def timestampLocal(dtUTC: DateTime): String = { // This is a laborious way to convert from UTC to local. There must be a better way. val instantUTC = dtUTC.getMillis val localDateTimeZone = DateTimeZone.getDefault val instantLocal = localDateTimeZone

Joda-Time: DateTime, DateMidnight and LocalDate usage

不羁的心 提交于 2019-12-03 06:36:54
问题 Joda-Time library includes different datetime classes DateTime - Immutable replacement for JDK Calendar DateMidnight - Immutable class representing a date where the time is forced to midnight LocalDateTime - Immutable class representing a local date and time (no time zone) I'm wondering how are you using these classes in your Layered Applications . I see advantages in having almost all the Interfaces using LocalDateTime (at the Service Layer at least) so that my Application doesn't have to

Default timezone for DateTime deserialization with Jackson (Joda-Time module)

最后都变了- 提交于 2019-12-03 05:55:32
This question is about deserialization to Joda-Time DateTime using jackson-datatype-joda module for Jackson . Is there a default timezone that date strings will be deserialized into? If so, what is it? Is it UTC ? I need to ask this because the Jackson documentation is not specific for Joda-Time DateTime. I found in this article ( http://wiki.fasterxml.com/JacksonFAQDateHandling ) that Jackson will assume GMT as the default time zone for deserializing into java.util.Date or java.util.Calendar . However, there is no mention of Joda-Time data types in this document. In addition, I specifically

How do I create a new Joda DateTime truncated to the last hour? [duplicate]

这一生的挚爱 提交于 2019-12-03 04:17:16
This question already has answers here : JodaTime equivalent of DateUtils.truncate() (4 answers) I am pulling timestamps from a file that I want to create a new DateTime for, but I want to create the DateTime at the floor of the hour (or any Joda Period will do). How Can I do this? Wohoo, found it. Simple like everything in Joda once I traced down the calls. DateTime dt = new DateTime().hourOfDay().roundFloorCopy(); 来源: https://stackoverflow.com/questions/1207957/how-do-i-create-a-new-joda-datetime-truncated-to-the-last-hour

Pattern String from a joda-time DateTimeFormatter?

老子叫甜甜 提交于 2019-12-03 01:55:27
Is it possible to get the pattern string from a joda-time DateTimeFormatter? DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd"); String originalPattern = formatter. ??? Joda Time does not provide a way to get the original pattern from a DateTimeFormatter. One reason is probably that a DateTimeFormatter wasn't necessarily created from a pattern; for example DateTimeFormat.forStyle() does not use patterns at all. However if you always use patterns, then you could wrap the DateTimeFormat class to record the pattern when the DateTimeFormatter is constructed. That way you can look

I am getting wrong time between two dates in Joda-Time

谁都会走 提交于 2019-12-03 01:21:38
问题 I am getting incorrect results whatever I do. Could anyone give me some advise please :). Here is the code of my program the is responsible for getting the time between two dates. I am getting a result but the problem is that it is incorrect and I have having trouble finding the problem. I have to Joda library in my project. if (timerightnow.isSelected()) { DateFormat getdate = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date getdate1 = new Date(); String datenow = getdate1.toString(); String

How to convert Joda Localdate to Joda DateTime?

假装没事ソ 提交于 2019-12-03 00:54:27
I'm trying to simply add TimeZone information back into a LocalDate before performing some more calculations. The LocalDate came from using the ObjectLab LocalDateCalculator to add days to an existing DateTime but the method needs to return a modified ReadableInstant to form an Interval which I can then inspect. The code I'm trying amounts to a conversion of Joda LocalDate to Joda DateTime: LocalDate contextLocalBusinessDate = calculator.getCurrentBusinessDate(); DateTime businessDateAsInContextLocation = new DateTime(contextLocalBusinessDate, contextTimeZone); The error I get is from Joda's