java get localdate tim from long code example
Example 1: get long from date java
String string_date = "12-December-2012";
SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy");
try {
Date d = f.parse(string_date);
long milliseconds = d.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
Example 2: java convert LocalDateTime to long
public long createTimestamp() {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.now().atZone(zoneId).toEpochSecond();
}