2

I'm trying to use DateTimeFormatter in my project, but Android Studio can't find java.time.format.DateTimeFormatter package.
I downloaded Java SE Development Kit 8u92 and in settings of my project I also set "use jdk8".
What am I missing?

Stephan Leila
  • 141
  • 1
  • 7
  • Why you don't use SimpleDateFormat. It's what I use in Android and it workd fine. – adalpari Jul 11 '16 at 10:12
  • SimpleDateFormat is what I am using in Android and it is not working fine. In particular it is unable to parse the time zone AEST (Australian Eastern Standard Time) which DateTimeFormatter apparently does: https://stackoverflow.com/questions/36473928/parse-date-with-aedt-and-aest-time-zone-in-java – Slartibartfast Jul 06 '18 at 07:57

2 Answers2

3

In Android, actually you are ussing Android SDK, not JDK directly. You could use SimpleDateFormat:

import java.text.SimpleDateFormat;

Date myDate = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.ZZZZ");
String date = dateFormat.format(myDate);
adalpari
  • 3,042
  • 18
  • 36
  • Oh, thanks for clarification. I like that in java 8 I can use `DateTimeFormatter.ISO_INSTANT` instead of hardcoding pattern myself – Stephan Leila Jul 11 '16 at 10:30
1

From official documentation about this class:

Since: 1.8

Android SDK is working over jvm 1.6

Related answer: Is it possible to use Java 8 for Android development?

Community
  • 1
  • 1
Rudziankoŭ
  • 9,663
  • 16
  • 80
  • 173