Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Last active April 27, 2019 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloprado/01924ca15f487a3100a26b99c021a122 to your computer and use it in GitHub Desktop.
Save juanpabloprado/01924ca15f487a3100a26b99c021a122 to your computer and use it in GitHub Desktop.
LocalDateTime Formatters on the Java Shell tool
jshell> import java.util.ArrayList;
jshell> import java.time.format.DateTimeFormatter; ^
jshell> ArrayList<DateTimeFormatter> ldtFormattersList = new ArrayList<>();
ldtFormattersList ==> []
jshell> ldtFormattersList.add(DateTimeFormatter.BASIC_ISO_DATE);
$57 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_LOCAL_DATE);
$58 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_LOCAL_TIME);
$59 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
$60 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_TIME);
$61 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_DATE);
$62 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_DATE_TIME);
$63 ==> true
jshell> ldtFormattersList.add(DateTimeFormatter.ISO_ORDINAL_DATE);
$64 ==> true
jshell> import java.time.LocalDateTime;
jshell> LocalDateTime ldt = LocalDateTime.now();
ldt ==> 2019-04-27T16:35:55.066751
jshell> ldtFormattersList.forEach(f -> {
...> System.out.println(ldt.format(f));
...> });
20190427
2019-04-27
16:35:55.066751
2019-04-27T16:35:55.066751
16:35:55.066751
2019-04-27
2019-04-27T16:35:55.066751
2019-117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment