jodatime

Correctly defining a duration using JodaTime

空扰寡人 提交于 2019-12-11 04:57:23
问题 I've created a method that takes two dates (in milliseconds) and returns a sentence that indicates the duration between these two dates. For the moment, I have this code: public static String formatDuration(long start, long end) { Interval interval = new Interval(start, end); return getPeriodFormatter().print(interval.toPeriod()).trim(); } private static PeriodFormatter getPeriodFormatter() { PeriodFormatter pf = new PeriodFormatterBuilder().printZeroRarelyFirst() .appendYears().appendSuffix(

get years, months, days from number of days on android

为君一笑 提交于 2019-12-11 03:29:55
问题 I want to get age in format years, months, and days; like this, x years and y months and z days . I was able to get days with this: LocalDate birthdate = new LocalDate (dob_yr, dob_mt, dob_dy); LocalDate now = new LocalDate(); Days nm_days = Days.daysBetween(birthdate, now); I tried using Log.d("days ", nm_days.getDays() +""); and this is what I got: 10365 How can I convert days to years months and days format? EDIT Ok. now I get something, but still doesn't really solve my problem, here it

Jodatime issues on Android 5.0

和自甴很熟 提交于 2019-12-11 03:16:18
问题 My app has been working for some time, but after the release of Android 5.0 it crashes on devices running this version. I'm using JodaTime 2.6 for date handling and it's this library that suddenly throws the following exception: java.lang.IllegalArgumentException: Invalid format: "6:06:00 AM" is malformed at "AM" Ive verified that the corresponding string I'm trying to parse has the correct format. UPDATE(Here is code that fails) private void doSomething(DateTime time, String timeToParse,int

Convert ISO 8601 Date to a Standard String Format

99封情书 提交于 2019-12-11 03:11:26
问题 I am trying to convert a valid ISO 8601 string to a consistent format so that sort and search using simple lexicographical order is possible. My application could receive a date/time in any of the following formats, for example: 2015-02-05T02:05:17.000+00:00 2015-02-05T02:05:17+00:00 2015-02-05T02:05:17Z These all represent the same date/time and I would like to convert them all to a canonical form for storage, say: 2015-02-05T02:05:17.000Z My first thought was to just parse them using a

NoClassDefFoundError Exception android joda time

Deadly 提交于 2019-12-11 02:36:04
问题 I am building an application and using Joda Time in it instead java built in Date/Time classes. but i am facing a problem that when i compile the app using Android API 22 it runs fine, but when i compile it with android API 23 it throws NoClassDefFoundError exception. My build.gradle is following apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '23.0.2' defaultConfig { multiDexEnabled true applicationId 'com.my.app' minSdkVersion 11 targetSdkVersion 23

Parsing date by multiple formats with pivotYear set up for 2 digit years

 ̄綄美尐妖づ 提交于 2019-12-11 02:16:39
问题 I am having trouble to implement "simple" parsing of a date. The requirement is to allow enter year in two or four digits. When two digits are entered then make the split date for deciding into what century it belongs the first of January next year. Here is what I have so far: DateTime now = new DateTime(); int pivotYear = now.getYear() - 49; // 2013 - 49 = 1964 where 49 is the DateTimeParser[] parsers = { DateTimeFormat.forPattern("dd/MM/yy").withPivotYear(pivotYear).withLocale(new Locale(

What is the right way to format Time between different timezones?

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:58:42
问题 I want to format time like 19:19:00 to different time zones. If I use SimpleDateFormat it always takes into account the start of the epoch: 1970.01.01. Some timezones have different offsets on the start of the epoch and now. For example, the default offset from Europe/Kiev now is UTC+0200 but in 1970 it was UTC+0300. That means if I run my server under Europe/Kiev the client which login under Europe/Berlin(UTC+0100) will see three hours different instead of two. I can solve this problem by

String to date (Invalid format)

假如想象 提交于 2019-12-10 23:41:33
问题 I am using Joda-Time library to convert my String dates to a real date, because this seemed like the easiest solution to do this. I am using the DateTime object to do this; new DateTime(strValue); But when inserting some formats it throws me the exception; java.lang.IllegalArgumentException: Invalid format: "Mon, 30 Sep 2002 01:56:02 GMT" java.lang.IllegalArgumentException: Invalid format: "Sun, 29 Sep 2002 19:59:01 GMT" java.lang.IllegalArgumentException: Invalid format: "Mon, 30 Sep 2002 01

Print from joda-time DateTimeFormatter with optional Parser

旧城冷巷雨未停 提交于 2019-12-10 22:39:57
问题 In a project using joda-time 2.1, I have the following DateTimeFormatter : /** * Parser for the "fraction" part of a date-time value. */ private static final DateTimeParser FRACTION_PARSER = new DateTimeFormatterBuilder() .appendLiteral('.') .appendFractionOfSecond(3, 9) .toParser(); /** * A formatter for a "local" date/time without time zone offset * (in the format "yyyy-dd-mmThh:mm:ss[.fff]"). */ private static final DateTimeFormatter FORMAT_LOCAL = new DateTimeFormatterBuilder() .append

Xstream's jodatime Local Date display

亡梦爱人 提交于 2019-12-10 20:28:14
问题 I'm using xstrem to serialise a jodatime local date into xml. However when output the generated xml the LocalDate is not in an easily readable format. See below: <date> <iLocalMillis>1316563200000</iLocalMillis> <iChronology class="org.joda.time.chrono.ISOChronology" reference="../../tradeDate/iChronology"/> Any ideas how I can get xstream to display the date in a format that won't drive me up the wall? 回答1: Here's what I have used successfully. I believe I used the info at the link mentioned