Created
August 11, 2012 20:28
-
-
Save dtrailin/3327027 to your computer and use it in GitHub Desktop.
Time class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Calendar; | |
| import java.util.GregorianCalendar; | |
| public class time { | |
| private int hour, minute, second; | |
| private static Calendar calendar; | |
| public String time(boolean Mil) { | |
| calendar = new GregorianCalendar(); | |
| hour = calendar.get(Calendar.HOUR_OF_DAY); | |
| minute = calendar.get(Calendar.MINUTE); | |
| second = calendar.get(Calendar.SECOND); | |
| if (Mil == false){ | |
| return String.format("%d:%02d:%02d %s", ((hour == 0 || hour == 12) ? 12 : hour % 12), minute, second, (hour > 12 ? "PM" : "AM")); | |
| } | |
| else { | |
| return String.format("%02d:%02d:%02d",hour , minute, second); | |
| } | |
| } | |
| public String toString(){ | |
| return time(false); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment