fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.temporal.* ;
  9. import java.time.format.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. DateTimeFormatter fDateOnly = DateTimeFormatter.ofPattern( "dd/MM/uuuu" );
  18. LocalDate ld = LocalDate.parse( "25/06/2019" , fDateOnly );
  19.  
  20. ZoneId z = ZoneId.of( "Africa/Tunis" );
  21. ZonedDateTime zdt = ld.atStartOfDay( z );
  22.  
  23. OffsetDateTime odt = zdt.toOffsetDateTime().withOffsetSameInstant( ZoneOffset.UTC );
  24.  
  25. DateTimeFormatter fIso8601DateTimeBasic = DateTimeFormatter.ofPattern( "uuuuMMdd'T'HHmmssX" );
  26. String output = odt.format( fIso8601DateTimeBasic );
  27.  
  28. System.out.println( "ld.toString(): " + ld );
  29. System.out.println( "zdt.toString(): " + zdt );
  30. System.out.println( "odt.toString(): " + odt );
  31. System.out.println( "output: " + output );
  32.  
  33. }
  34. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
ld.toString(): 2019-06-25
zdt.toString(): 2019-06-25T00:00+01:00[Africa/Tunis]
odt.toString(): 2019-06-24T23:00Z
output: 20190624T230000Z