Created
November 17, 2017 00:49
-
-
Save KirillKudaev/c4a1235b5d5ea09d3e14f2d228739d2b to your computer and use it in GitHub Desktop.
Epoch Java
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
package PrinFoodPlus.Utils; | |
import PrinFoodPlus.Controller; | |
import javafx.application.Platform; | |
import javafx.scene.control.Alert; | |
import javafx.scene.control.ButtonType; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Optional; | |
import java.util.TimeZone; | |
public class PrinFoodUtils { | |
public static String getEpochToDay(int daysAhead) { | |
Calendar cal = Calendar.getInstance(); | |
cal.setTimeZone(TimeZone.getTimeZone("CST")); | |
cal.set(Calendar.HOUR_OF_DAY, 0); | |
cal.set(Calendar.MINUTE, 0); | |
cal.set(Calendar.SECOND, 0); | |
cal.set(Calendar.MILLISECOND, 0); | |
cal.add(Calendar.DATE, daysAhead); | |
return String.valueOf(cal.getTimeInMillis()); | |
} | |
public static long convertDateToEpoch(String date) { | |
Calendar cal = null; | |
try { | |
cal = Calendar.getInstance(); | |
cal.setTimeZone(TimeZone.getTimeZone("CST")); | |
cal.setTime(new SimpleDateFormat("MM/dd/yyyy").parse(date)); | |
cal.set(Calendar.HOUR_OF_DAY, 0); | |
cal.set(Calendar.MINUTE, 0); | |
cal.set(Calendar.SECOND, 0); | |
cal.set(Calendar.MILLISECOND, 0); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
return cal.getTimeInMillis(); | |
} | |
public static String decapitalize(String string) { | |
if (string == null || string.isEmpty()) | |
return string; | |
char c[] = string.toCharArray(); | |
c[0] = Character.toLowerCase(c[0]); | |
return new String(c); | |
} | |
public static Runnable confirmClosingAction() { | |
return () -> { | |
if (Controller.madeChanges) { | |
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); | |
alert.setTitle("Close without committing?"); | |
alert.setHeaderText("You're about to close without committing\nany of your changes."); | |
alert.setContentText("Are you sure you want to exit without\ncommitting changes?"); | |
Optional<ButtonType> result = alert.showAndWait(); | |
if (result.isPresent() && result.get() == ButtonType.OK) { | |
Platform.exit(); | |
System.exit(0); | |
} | |
} else { | |
System.exit(0); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment