jodatime

Why is Joda Time serialized form so large, and what to do about it?

梦想与她 提交于 2019-12-12 11:53:36
问题 On my machine, the following code snippet: DateTime now = DateTime.now(); System.out.println(now); System.out.println("Date size:\t\t"+serialiseToArray(now).length); System.out.println("DateString size:\t"+serialiseToArray(now.toString()).length); System.out.println("java.util.Date size:\t"+serialiseToArray(new Date()).length); Duration twoHours = Duration.standardHours(2); System.out.println(twoHours); System.out.println("Duration size:\t\t"+serialiseToArray(twoHours).length); System.out

Does Jodatime have a method to get the months and days since some older date?

对着背影说爱祢 提交于 2019-12-12 11:43:06
问题 I would like to know exactly how many months and days(possibly years) some older date is from today. Is there a method to do that? I know how to get the difference of the months, I know how to get the difference in days. But I am unable to get the months and the days. Ex: old = '2013-03-04' now = '2013-04-17' so the result im looking for is something like 1 month(s) and 13* day(s) *maybe its 12 im not every sure. 回答1: This can be done by using Period in JodaTime. For example, LocalDate old =

Converting from java.util.TimeZone to org.joda.DateTimeZone

拈花ヽ惹草 提交于 2019-12-12 10:54:18
问题 How is it possible in Java to convert an instance of java.util.TimeZone to org.joda.DateTimeZone and keeping the daylight saving time? 回答1: Joda-Time in maintenance-mode The Joda-Time project, now in maintenance mode, advises migration to the java.time classes. java.time.ZoneId The modern replacement for java.util.TimeZone is java.time.ZoneId & java.time.ZoneOffset. You should avoid the old legacy date-time classes. But if necessary, you can convert to/from the java.time types. Look to new

Can't get correct current islamic date

时光总嘲笑我的痴心妄想 提交于 2019-12-12 09:38:42
问题 i am using joda time to get current islamic date in Saudi Arabia as in their website: DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0); DateTime dtIslamic = dtISO.withChronology(IslamicChronology.getInstance()); above prints the day less than the actual day, it prints that today is 7 but actual is 8. please advise. UPDATE: i even tried it with timezone as follows: DateTimeZone SAUDI_ARABIA = DateTimeZone.forID("Asia/Riyadh"); DateTime dtISO = new DateTime(2014, 1, 9, 0, 0, 0, 0);

need flexible datetime conversion with joda

空扰寡人 提交于 2019-12-12 09:35:11
问题 I want to use joda to parse datetime strings in emails. Unfortunately I get all kinds of different formats, for example Wed, 19 Jan 2011 12:52:31 -0600 Wed, 19 Jan 2011 10:15:34 -0800 (PST) Wed, 19 Jan 2011 20:03:48 +0000 (UTC) Wed, 19 Jan 2011 17:02:08 -0600 (CST) Fri, 21 Jan 2011 10:39:55 +0100 (CET) Fri, 21 Jan 2011 17:50:42 -0500 (EST) Wed, 06 Apr 2011 15:38:25 GMT Thu, 7 Apr 2011 11:38:24 +0200 Fri, 8 Apr 2011 05:13:36 -0700 (MST) 20 Apr 2011 03:00:46 -0400 The code below catches most of

Joda time bug on certain Android devices?

家住魔仙堡 提交于 2019-12-12 08:58:15
问题 I'm using joda-time 1.6.2 in an Android app and I am getting some crash reports java.lang.IllegalArgumentException: Invalid format: "8:00 AM" is malformed at "AM" And the code that triggers is is the following: DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm a"); LocalTime lt = formatter.parseDateTime(value).toLocalTime(); I can't reproduce this crash on my phones so it happens only on certain Android devices and I have no clue why. 回答1: I was faced with the same issue after

UTC Timestamp + Joda Time

夙愿已清 提交于 2019-12-12 08:54:07
问题 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

How to compare Joda DateTime objects with acceptable offset (tolerance)?

陌路散爱 提交于 2019-12-12 08:50:05
问题 I wonder is there any standard API in JodaTime to compare 2 DateTime objects with specified tolerance? I am looking for a one-liner preferably by using Joda standard API. Not for time-aritmethic expressions like in this post. Ideally, it would be something like: boolean areNearlyEqual = SomeJodaAPIClass.equal(dt1, dt2, maxTolerance); Thanks! 回答1: Use this: new Duration(dt1, dt2).isShorterThan(Duration.millis(maxTolerance)) 回答2: This post is old, but I find the line in the accepted solution a

JodaTime DateTime, ISO8601 GMT date format

懵懂的女人 提交于 2019-12-12 08:20:01
问题 How can I get the following format: 2015-01-31T00:00:00Z (ISO8601 GMT date format) Out of a DateTime object in joda time (java) ? Eg. DateTime time = DateTime.now(); String str = // Get something like 2012-02-07T00:00:00Z Thanks! :) 回答1: The JODA Javadoc indicates that toString for DateTime outputs the date in ISO8601. If you need to have all of the time fields zeroed out, do this: final DateTime today = new DateTime().withTime(0, 0, 0, 0); System.out.println(today); That will include

Joda parse ISO8601 date in GMT timezone

折月煮酒 提交于 2019-12-12 08:19:36
问题 I have a ISO 8601 date, lets say: 2012-01-19T19:00-05:00 My machine timezone is GMT+1 I'm trying to use joda to parse this and convert it to the respective GMT date and time: DateTimeFormatter simpleDateISOFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mmZZ"); creationDate = simpleDateISOFormat.withZone(DateTimeZone.UTC) .parseDateTime(date + "T" + time) .toDate(); Now the result that I'm expecting is Fri Jan 20 00:00:00 CET 2012 Instead I'm getting: Fri Jan 20 01:00:00 CET 2012 I