Last active
November 20, 2017 21:27
-
-
Save dixsonhuie/ca4e2eb697e8827f691accc6881f2198 to your computer and use it in GitHub Desktop.
java snippets
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
// get the supported ids for GMT-05:00 (Eastern Standard Time) | |
String[] ids = TimeZone.getAvailableIDs(-5 * 60 * 60 * 1000); | |
// if no ids were returned, something is wrong. get out. | |
if (ids.length == 0) | |
System.exit(0); | |
// begin output | |
System.out.println("Current Time:"); | |
// create a Eastern Standard Time time zone | |
SimpleTimeZone edt = new SimpleTimeZone(-5 * 60 * 60 * 1000, ids[0]); | |
// set up rules for Daylight Saving Time | |
edt.setStartRule(Calendar.MARCH, 8, -Calendar.SUNDAY, 2 * 60 * 60 * 1000); | |
edt.setEndRule(Calendar.NOVEMBER, 1, -Calendar.SUNDAY, 2 * 60 * 60 * 1000); | |
// create a GregorianCalendar with the Eastern Daylight time zone | |
// and the current date and time | |
Calendar calendar = new GregorianCalendar(edt); | |
Date trialTime = new Date(); | |
calendar.setTime(trialTime); | |
String s = String.format("Today: %1$tm/%1$te/%1$tY %1$tH.%1$tM.%1$tS", calendar); | |
System.out.println(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment