Created
February 17, 2015 11:58
-
-
Save uttesh/ef9028cefd7f4345b790 to your computer and use it in GitHub Desktop.
Find the given date and timezone is DST or NOT
This file contains 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.Date; | |
import java.util.SimpleTimeZone; | |
import java.util.TimeZone; | |
/** | |
* | |
* @author Rivet Systems | |
*/ | |
public class FindDST { | |
public static void main(String[] args) { | |
Calendar time = Calendar.getInstance(); | |
time.set(2014, 11, 1, 6, 00); | |
if (isDayLightSaving("CET", time.getTime())) { | |
System.out.println("Its in DST"); | |
} else { | |
System.out.println("Its NOT in DST"); | |
} | |
} | |
public static boolean isDayLightSaving(String timezone, Date dateStr) { | |
boolean isDST = false; | |
TimeZone iTimezone = TimeZone.getTimeZone(timezone); | |
System.out.println("Timezone : " + iTimezone.getDisplayName()); | |
System.out.println("dateStr : " + dateStr); | |
SimpleTimeZone stz = new SimpleTimeZone(iTimezone.getRawOffset(), | |
timezone, | |
Calendar.MARCH, 8, -Calendar.SUNDAY, | |
2 * 60 * 60 * 1000, | |
Calendar.NOVEMBER, 1, -Calendar.SUNDAY, | |
2 * 60 * 60 * 1000, 60 * 60 * 1000); | |
if (stz.inDaylightTime(dateStr)) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment