Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Date; //import Date class
- class ShowTime {
- public static void main (String [] args) {
- while (true) { // Run infinity print
- try {
- Date now = new Date();
- String ab;
- switch (Integer.parseInt(String.format("%te",now))%10) { // Find case of some days that ended with 1, 2, or 3
- case 1 : ab = "st";
- break;
- case 2 : ab = "nd";
- break;
- case 3 : ab = "rd";
- break;
- default : ab = "th";
- }
- System.out.printf("Today is: %te%2s of %tB in %tY at %tr\n", now, ab, now, now, now); // Print each line
- Thread.sleep(1000); //stop the program for 1000 milliseconds or 1 second
- } catch (Exception e) {
- System.out.println("Got Exception!"); // print when the program has an error
- }
- }
- }
- }
- // try-catch is require
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement