Created
April 5, 2019 15:49
-
-
Save bmaggi/ce46c721d17b7ed8c7608d6d6199ffd8 to your computer and use it in GitHub Desktop.
Example of date change (France,Brasil)
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.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.time.Duration; | |
import java.util.Date; | |
import java.util.TimeZone; | |
class TimeChange { | |
public static void main(String[] args) throws ParseException { | |
timeForward("Europe/Paris", "2019-03-31 01:59:59", Duration.ofSeconds(2).toMillis()); // FRANCE +1 | |
timeForward("Europe/Paris", "2018-10-28 01:59:59", Duration.ofHours(1).toMillis() + Duration.ofSeconds(2).toMillis()); // FRANCE -1 | |
timeForward("America/Sao_Paulo", "2019-11-02 23:59:59", Duration.ofSeconds(2).toMillis()); // BRASIL + 1 | |
timeForward("America/Sao_Paulo", "2019-02-16 22:59:59", Duration.ofHours(1).toMillis() + Duration.ofSeconds(2).toMillis()); // BRASIL - 1 | |
} | |
public static void timeForward(String timeZone, String begin, long timeforward) throws ParseException { | |
DateFormat simpleDateFormatWithTimeZone = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
simpleDateFormatWithTimeZone.setTimeZone(TimeZone.getTimeZone(timeZone)); | |
final Date date = simpleDateFormatWithTimeZone.parse(begin); | |
final long time = date.getTime(); | |
long endTime = time + Duration.ofSeconds(2).toMillis(); | |
System.out.println(begin + " -(+" + timeforward + " ms)-> " + simpleDateFormatWithTimeZone.format(new Date(endTime))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment