Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Proposal for Easy Challenge #118
package fr.daniel.dateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class DateFormat {
private static Map<String, String> linkJavaISO = new HashMap<>();
static {
linkJavaISO.put("%l", "%1\\$tL");
linkJavaISO.put("%s", "%1\\$tS");
linkJavaISO.put("%m", "%1\\$tM");
linkJavaISO.put("%h", "%1\\$tI");
linkJavaISO.put("%H", "%1\\$tH");
linkJavaISO.put("%c", "%1\\$tp");
linkJavaISO.put("%d", "%1\\$td");
linkJavaISO.put("%M", "%1\\$tm");
linkJavaISO.put("%y", "%1\\$tY");
public static String dateFromISO(String format){
for (Entry<String, String> entry : linkJavaISO.entrySet()){
format = format.replaceAll(entry.getKey(), entry.getValue());
return String.format(format, Calendar.getInstance());
public static void main(String[] args) {
System.out.println(dateFromISO("%s:%m:%h %M/%d/%y"));
System.out.println(dateFromISO("The minute is %m! The hour is %h."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment