Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/mycmd/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private static void registerCommands(Map<String, Command> 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());
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/mycmd/commands/TimeCommand.java
Original file line number Diff line number Diff line change
@@ -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);
}
}