java convert LocalDateTime to long
public long createTimestamp() {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.now().atZone(zoneId).toEpochSecond();
}
java convert LocalDateTime to long
public long createTimestamp() {
ZoneId zoneId = ZoneId.systemDefault();
return LocalDateTime.now().atZone(zoneId).toEpochSecond();
}
java localdatetime get milliseconds
#Date and time as String to Long (millis):
String dateTimeString = "2021-09-12T16:55:18.000Z";
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
LocalDateTime localDateTime = LocalDateTime
.parse(dateTimeString, formatter);
Long dateTimeMillis = localDateTime
.atZone(ZoneId.systemDefault())
.toInstant()
.toEpochMilli();
You can then use the number of milliseconds to convert it to a date object:
var msec = Date.parse("March 21, 2012");
var d = new Date(msec);
document.getElementById("demo").innerHTML = d;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us