Advertisement
damoncard

GetCurrentTime&Date

Jan 21st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.Date; //import Date class
  2. class ShowTime {
  3.   public static void main (String [] args) {
  4.     while (true) { // Run infinity print
  5.       try {
  6.         Date now = new Date();
  7.         String ab;
  8.         switch (Integer.parseInt(String.format("%te",now))%10) { // Find case of some days that ended with 1, 2, or 3
  9.           case 1 : ab = "st";
  10.                     break;
  11.           case 2 : ab = "nd";
  12.                     break;
  13.           case 3 : ab = "rd";
  14.                     break;
  15.           default : ab = "th";
  16.         }
  17.         System.out.printf("Today is: %te%2s of %tB in %tY at %tr\n", now, ab, now, now, now); // Print each line
  18.         Thread.sleep(1000); //stop the program for 1000 milliseconds or 1 second
  19.       } catch (Exception e) {
  20.         System.out.println("Got Exception!"); // print when the program has an error
  21.       }
  22.     }
  23.   }
  24. }
  25. // try-catch is require
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement