Questions tagged [threetenbp]

ThreeTen-Backport is the backport of JSR-310 to Java SE 7. Questions about "java.time" in Java SE 8 should use the [java-time] tag. Only questions specifically about the backport should use this tag.

ThreeTen-Backport is the backport of JSR-310 to Java SE 7. Questions about java.time in Java SE 8 should use the tag. Only questions specifically about the backport should use this tag.

95 questions
230
votes
3 answers

How to use ThreeTenABP in Android Project

I'm using Android Studio 2.1.2 and my Java setup is the following: >java -version > openjdk version "1.8.0_91" > OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~15.10.1-b14) > OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode) I…
kael
  • 6,585
  • 5
  • 21
  • 27
58
votes
6 answers

Motorola devices : org.threeten.bp.DateTimeException when parsing a date in ThreeTen

I have a very weird behaviour on some Motorola devices where LocalDateTime.now() is returning 0000-00-00T00:00:00.0 with ThreeTenABP. The code is as follow: @Override protected void onResume() { super.onResume(); if…
Romain Piel
  • 11,017
  • 15
  • 71
  • 106
54
votes
5 answers

ThreeTen-Backport error on Android - ZoneRulesException: No time-zone data files registered

I'm using ThreeTen-Backport library for my Android project (because java.time is not yet implemented in android development). When I write LocalDate today=LocalDate.now(); or LocalTime time=LocalTime.now(); I get the following exception: Caused…
Matan Itzhak
  • 2,702
  • 3
  • 16
  • 35
26
votes
2 answers

How to convert ZonedDateTime/OffsetDateTime to Date using ThreeTenABP?

Using the ThreeTen Android Backport library, what is the simplest way to convert a ZonedDateTime or OffsetDateTime into an old-school java.util.Date instance? If I had full Java 8 libs at my disposal, this of course would be the way to do it (as in…
Jonik
  • 80,077
  • 70
  • 264
  • 372
22
votes
1 answer

How to convert LocalDateTime object into ISO string including time zone?

I am trying to convert a date/time string back and forth into a LocalDateTime object. I am using ThreeTenBp as the date/time library. String -> LocalDateTime val actual = LocalDateTime.parse("2016-12-27T08:15:05.674+01:00", …
JJD
  • 50,076
  • 60
  • 203
  • 339
17
votes
1 answer

Need to find days difference between two org.threeten.bp.LocalDateTime dates in java

I have two dates in an org.threeten.bp.LocalDateTime object. I need to find the difference between these two dates in terms of days.
gaurav
  • 189
  • 2
  • 6
13
votes
1 answer

How to convert from Date to LocalDate when using ThreeTenABP?

NOTE: This is answered already excellently in the JDK world here, but the accepted answer doesn't apply to the Android port of JSR-310 which doesn't have that extended API for Date. So, what is the best way to convert a java.util.Date to…
Alex Florescu
  • 5,096
  • 1
  • 28
  • 49
13
votes
3 answers

how to convert from ZonedDateTime to Joda DateTime

I've switched to threeten for date times but I've still got a 3rd party tool that uses joda to write timestamp with timezone to the database and I need to convert from one to the other. What's the best way? As a workaround I tried…
Tim Pigden
  • 895
  • 2
  • 9
  • 18
12
votes
7 answers

Calcuting the date difference for a specified number of days using LocalDate class

I'm using openjdk version 1.8.0_112-release for development but will need to support previous JDK versions too (pre-Java-8) - so can't use java.time. I am writing a utitily class to calculate the date to see if a saved date is before the current…
ant2009
  • 27,094
  • 154
  • 411
  • 609
10
votes
1 answer

How to unit test code which makes use of ZoneId.systemDefault without raising org.threeten.bp.zone.ZoneRulesException

I have the following application code. Application code public static long advanceByMax1HourWithoutOverflow(long currentTimeMillis) { ZoneId zoneId = ZoneId.systemDefault(); ZonedDateTime zonedDateTime =…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
8
votes
1 answer

Comparing ThreeTen backport to JSR-310

For some reasons, we can't use java 8 right now - we're still stuck at java 7. However, I'd like to use the new JSR-310 date/time APIs right now, using the official backport ThreeTen. Its homepage states: The backport is NOT an implementation of…
MRalwasser
  • 15,605
  • 15
  • 101
  • 147
7
votes
0 answers

org.threeten.bp.format.DateTimeParseException: Text could not be parsed at index

I'm receiving the date in the below format: "Deadline": "2019-07-05T16:30:00" And I'm trying to parse it using below formatter: private val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH) But…
Aditya Tyagi
  • 431
  • 3
  • 8
7
votes
1 answer

How to initialize ThreeTen Android backport in a Unit test

I use this library for storing date & time related data in my app. When the application starts, AndroidThreeTen is initialized first to function properly. So I want to ask how to initialize it when unit testing? E.g. I want to test using LocalDate,…
Fawwaz Yusran
  • 1,260
  • 2
  • 19
  • 36
6
votes
3 answers

How can I convert a org.threeten.bp.OffsetDateTime to java.time.OffsetDateTime?

I'm using a client library (third party, not mine, cannot change) which utilizes the ThreeTen date types. My project is Java 11 and uses Java 8 date types. What is the recommended way to convert ThreeTeen objects to their Java 8 counterparts?
6
votes
1 answer

How to ignore java.time package in Android Studio

I am currently working on an Android Studio project with a minimum API version of 17 (JellyBean), so I cannot use the java.time package. Instead, I am using the ThreeTen backport for Android (com.jakewharton.threetenabp:threetenabp:1.1.0). My…
Leo Aso
  • 11,898
  • 3
  • 25
  • 46
1
2 3 4 5 6 7