jodatime

Change timezone of Date object without changing date

百般思念 提交于 2019-12-04 17:16: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. Basil Bourque tl;dr ZonedDateTime zdtMontreal = ZonedDateTime.now( ZoneId.of( "America/Montreal" ) ); ZonedDateTime zdtAuckland = zdtMontreal.withZoneSameLocal( ZoneId.of( "Pacific/Auckland" ) ); Not the same moment. The zdtAuckland moment occurred several hours earlier . Be

Comparing two Joda-Time DateTime objects

旧街凉风 提交于 2019-12-04 16:13:29
问题 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 " +

How to convert DateTime to Date

徘徊边缘 提交于 2019-12-04 15:42:47
问题 How can I convert Date to DateTime and vice versa? E.g. Date dt = new Date(); Now I want to covert this to DateTime . Also DateTime dtim = new DateTime(); Now I want to convert it to Date. 回答1: Is this Joda Time 's DateTime you're talking about? If so, it will be dateTime.toDate() 回答2: I guess you convert it to UTC via Date.getTime(). And after that, use a constructor/setter on the other object. 回答3: As skaffman said above dateTime.toDate() should do the trick. But keep in mind that if the

Jackson, Retrofit, JodaTime deserialization

好久不见. 提交于 2019-12-04 14:11:10
I'm using those three libraries: retrofit, jackson and jodatime, and I'm trying somethings to deserialize my object when it comes from my rest api, but I could not figure out how to solve this, here goes the json returned by rest api: { "establishment": "Gold Ball Confraria", "idCardPayment": 0, "paymentDate": "/Date(1461208761970+0000)/", "total": 10 } and that is the class that I've tried to deserialize my object: public class PaymentHistoryItemApiResult { @JsonProperty("total") private double totalValue; @JsonProperty("establishment") private String establishmentName; @JsonDeserialize(using

How to check if a list of intervals (Joda-Time) fully covers a month in Java

别等时光非礼了梦想. 提交于 2019-12-04 10:44:46
I'm using Joda-Time library in Java to keep track a list of time intervals . I want to check if a list of Interval objects fully covers every minute of a month. There's about 30 intervals of varying length from a few hours to a few days. I thought a cheap way to do this is to sort the list of intervals by start time, then successively check if there is a break between the intervals within the range of the month. If yes, then the month is not fully covered. I'm stuck on the first part, sorting the list. I planned to use Arrays .sort(), but it needs the elements to implement the comparable

Custom Marshalling from Java to Flex via BlazeDS

孤者浪人 提交于 2019-12-04 08:20:42
问题 My team are putting together a proof-of-concept Flex application sitting on top of a Spring-based server using BlazeDS. We do quite a lot of date calculations, so we use Joda Time extensively throughout the code and in our domain model. We're now trying to figure out how we can continue to use Joda Time in our DTOs that are sent back-and-forth with the Flex frontend via BlazeDS. Our goal is to use the Actionscript 3 data type Date on the Flex side and have that map to our use of Joda time's

MySQL DATETIME precision (joda-time, Hibernate, org.jadira.usertype, hbm2ddl)

天涯浪子 提交于 2019-12-04 07:43:28
In my hibernate-4 entity, I am mapping a joda-time DateTime property using the recommended jadira usertypes : @Entity @Table(name="timing") public class TimingEntity { ... @Basic(optional=false) @Column(name="moment") @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") public DateTime getMoment() { ... My database is MySQL. With hibernate property hbm2ddl.auto set to create value, I have the following column generated in my timing table: CREATE TABLE `timing` ( ... `moment` DATETIME NOT NULL, ... ) The generated CREATE TABLE contains the DATETIME column. The DATETIME in MySQL

UTC Timestamp + Joda Time

我们两清 提交于 2019-12-04 07:41:16
I am trying to get the UTC TimeStamp in a simple Java program using Joda: public Timestamp getCurrentUTC(LocalDateTime date, DateTimeZone srcTZ, DateTimeZone dstTZ, Locale l) { DateTime srcDateTime = date.toDateTime(srcTZ); DateTime dstDateTime = srcDateTime.toDateTime(dstTZ); System.out.println("UTC Time:" + dstDateTime.getMillis()); System.out.println("UTC Time:" + new Timestamp(dstDateTime.getMillis())); return new Timestamp(dstDateTime.getMillis()); } The output of the program is as follows: UTC Time:1378265162047 UTC Time:2013-09-03 23:26:02.047 The millisecond value is the correct UTC

How to check if current date is between two reoccurring dates in java? [duplicate]

家住魔仙堡 提交于 2019-12-04 07:08:26
问题 This question already has answers here : How can I determine if a date is between two dates in Java? [duplicate] (11 answers) Closed 4 years ago . I am trying to create an app, and got stuck at calculating if today is in the school year. The user enters two dates, with no year, that reoccur annually . These are the start and end dates of the school year. I want to check if the current date, is between these two, even if it overlaps two years. So if school starts on November, and ends on june,

migrate from Joda time library to Java time(Java 8)

社会主义新天地 提交于 2019-12-04 07:06:44
I am trying to migrate from Joda time library to Java time (Java 8). I am unable to find equivalent of ISODateTimeFormat.dateOptionalTimeParser() in java.time Joda ISO formatter has nice parsers: ISODateTimeFormat.dateTimeParser() : generic - selects parser based on string parsed. Similarly: ISODateTimeFormat.dateOptionalTimeParser() . I am finding it difficult to change Joda time to java.time. Can some one guide me? example: String dateTimeString = "2015-01-01T12:29:22+00:00"; String dateTimeString2 = "2015-01-01T12:29:22"; When I parse this string using joda time then ISODateTimeFormat