Last active
February 25, 2016 01:28
-
-
Save ainvyu/45dd021e86c9c981bef5 to your computer and use it in GitHub Desktop.
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
@Test | |
public void timezoneTest() throws Exception { | |
long slotSize = 86400000; // ms -> 1day | |
Calendar caldendar = Calendar.getInstance(); | |
long origCurTime = caldendar.getTimeInMillis(); | |
caldendar.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); | |
long curTime = caldendar.getTimeInMillis(); | |
long tzOffset = TimeZone.getDefault().getRawOffset(); | |
long curTimeWithTimeZone = curTime + tzOffset; | |
long offset = curTimeWithTimeZone % slotSize; | |
long biTime = curTime - offset - slotSize; | |
System.out.println(String.format("orig curTime: %d", origCurTime)); | |
System.out.println(String.format("curTime: %d", curTime)); | |
System.out.println(String.format("tzOffset: %d", tzOffset)); | |
System.out.println(String.format("curTimeWithTimeZone: %d", curTimeWithTimeZone)); | |
System.out.println(String.format("offset: %d", offset)); | |
System.out.println(String.format("biTime: %d", biTime)); | |
System.out.println(String.format("biTime date: " + new Date(biTime) )); | |
System.out.println(String.format("orig date: " + caldendar.getTime() )); | |
System.out.println("################################################################################"); | |
ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.of("Asia/Seoul")); | |
System.out.println(String.format("orig date: " + now)); | |
System.out.println(String.format("orig date (millisec): " + now.toInstant().toEpochMilli())); | |
ZonedDateTime startOfDayInYesterday = now.minusDays(1) | |
.withHour(0) | |
.withMinute(0) | |
.withSecond(0) | |
.withNano(0); | |
System.out.println(String.format("biTime date: " + startOfDayInYesterday)); | |
System.out.println(String.format("biTime date: " + | |
startOfDayInYesterday.toInstant().toEpochMilli())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
orig curTime: 1456363640552
curTime: 1456363640552
tzOffset: 32400000
curTimeWithTimeZone: 1456396040552
offset: 37640552
biTime: 1456239600000
biTime date: Wed Feb 24 00:00:00 KST 2016
orig date: Thu Feb 25 10:27:20 KST 2016
orig date: 2016-02-25T10:27:20.594+09:00[Asia/Seoul]
orig date (millisec): 1456363640594
biTime date: 2016-02-24T00:00+09:00[Asia/Seoul]
biTime date: 1456239600000