Created
December 1, 2017 06:52
-
-
Save brake/91f1cf58c14d71d9b235f3a764f412a9 to your computer and use it in GitHub Desktop.
Java Date to Google Sheets Date converter
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.Date; | |
| import java.util.concurrent.TimeUnit; | |
| public class GoogleSheetsDate { | |
| private static final long SHEETS_EPOCH_DIFFERENCE = 2209161600000L; | |
| static double fromJavaDate(Date date) { | |
| // https://stackoverflow.com/a/38015954/5525962 | |
| long millisSinceUnixEpoch = date.getTime(); | |
| long millisSinceSheetsEpoch = millisSinceUnixEpoch + SHEETS_EPOCH_DIFFERENCE; | |
| return millisSinceSheetsEpoch / (double) TimeUnit.DAYS.toMillis(1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment