Skip to content

Commit d447025

Browse files
Merge pull request #14 from nihaltp/feat/time
Add TimeCommand to display the current time
2 parents 84e529e + e443ac5 commit d447025

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/main/java/com/mycmd/App.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private static void registerCommands(Map<String, Command> commands) {
5151
commands.put("help", new HelpCommand(commands));
5252
commands.put("exit", new ExitCommand());
5353
commands.put("ver", new VersionCommand());
54+
commands.put("time", new TimeCommand());
5455
commands.put("date", new DateCommand());
5556
}
5657
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
import java.time.LocalTime;
6+
import java.time.format.DateTimeFormatter;
7+
8+
public class TimeCommand implements Command {
9+
@Override
10+
public void execute(String[] args, ShellContext context) {
11+
LocalTime now = LocalTime.now();
12+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H.mm.ss.SS");
13+
String formattedTime = now.format(formatter);
14+
System.out.println("The current time is: " + formattedTime);
15+
}
16+
}

0 commit comments

Comments
 (0)