1

I have extracted a batch start date property this way:

Configuration conf = new Configuration(false);
conf.addResource(new Path(System.getProperty("oozie.action.conf.xml"))); 
String batchStartDate = conf.get("batch.start.date");

I want it to be in UTC. So I've created a DateTimeFormatter:

DateTimeFormatter dateTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC);

If I call something like dateTimeFormat.parseDateTime(batchStartDate), it returns DateTime while I need a string. Is it a proper approach to just call dateTime.toString();? Or maybe it's better to go with dateTimeFormat.print(dateTime); ?

samba
  • 2,821
  • 6
  • 30
  • 85
  • Depend the format you need ,toString has a default one but not mandatory the one you want – azro Jun 21 '18 at 11:21
  • Using Joda-Time? May mention it and add the jodatime tag. In any case you probably need to two formatters, one for parsing the format you got and one for formatting into the one you want. You may also want to use `java.time` since Joda-Time is in maintenance mode. UTC is not a format. Could you be more precise about the format you want? – Ole V.V. Jun 21 '18 at 11:26
  • If `toString` gives you what you want, that’s fine. If not, use a formatter for formatting. – Ole V.V. Jun 21 '18 at 11:30
  • Possible duplicate of [How to format Joda-Time DateTime to only mm/dd/yyyy?](https://stackoverflow.com/questions/20331163/how-to-format-joda-time-datetime-to-only-mm-dd-yyyy) I know you don’t want MM/dd/yyyy, but the technique would be the same. – Ole V.V. Jun 21 '18 at 11:31
  • Isn’t the batch start date from Oozie in UTC already? I’m sorry I don’t understand what you want. Maybe if you give an example of the batch start date and the string you would like to have from it, it could help. – Ole V.V. Jun 22 '18 at 17:12
  • @OleV.V. At first I thought that it's in a format like that `yyyy-MM-dd'T'HH:mm:ssZZZ`. But after some research I could not verify my assumption though. – samba Jun 25 '18 at 08:06
  • It’s probably matching Java’s built-in [`ISO_OFFSET_DATE_TIME`](https://docs.oracle.com/javase/9/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME), then. Just a guess, though. Sorry, I’m not a Joda-Time user and don’t know the equivalent. – Ole V.V. Jun 25 '18 at 08:11

0 Answers0