diff --git a/src/main/java/com/mycmd/App.java b/src/main/java/com/mycmd/App.java index e6c301a..e6a79a8 100644 --- a/src/main/java/com/mycmd/App.java +++ b/src/main/java/com/mycmd/App.java @@ -51,6 +51,7 @@ private static void registerCommands(Map commands) { commands.put("help", new HelpCommand(commands)); commands.put("exit", new ExitCommand()); commands.put("ver", new VersionCommand()); + commands.put("time", new TimeCommand()); commands.put("date", new DateCommand()); } } diff --git a/src/main/java/com/mycmd/commands/TimeCommand.java b/src/main/java/com/mycmd/commands/TimeCommand.java new file mode 100644 index 0000000..10ab142 --- /dev/null +++ b/src/main/java/com/mycmd/commands/TimeCommand.java @@ -0,0 +1,16 @@ +package com.mycmd.commands; + +import com.mycmd.Command; +import com.mycmd.ShellContext; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +public class TimeCommand implements Command { + @Override + public void execute(String[] args, ShellContext context) { + LocalTime now = LocalTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H.mm.ss.SS"); + String formattedTime = now.format(formatter); + System.out.println("The current time is: " + formattedTime); + } +}